//
//  ProductDetailViewController.m
//  PurchasingMeeting
//
//  Created by zhuang yihang on 7/17/13.
//  Copyright (c) 2013 YX. All rights reserved.
//

#import "ProductDetailViewController.h"
#import "ProductObject.h"
#import "NumberInputView.h"
#import "DataManager.h"
#import "SizeObject.h"
#import "OrderObject.h"
#import "PictureViewController.h"
#import "ShopViewController.h"
#import "FPPopoverController.h"
#import "SuitViewController.h"
#import "DetailcellView.h"

#import "TKImageCache.h"
#import "PMGlobal.h"

@interface ProductDetailViewController (){
    ProductObject *product_;
    
    TKImageCache *imageCache_;
    
    NSArray* sizeType;
}

@end

@implementation ProductDetailViewController
@synthesize scroll;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initWithProduct:(ProductObject *)product objtag:(int)objtag tag:(int)tag{
    self = [super init];
    if (self) {
        [self setNavTitle:@"产品详情"];
        obj = product;
        numobjtag = objtag;
        numtag = tag;
        shop = [[DataManager sharedManager]getShopList];
        user = [[DataManager sharedManager]getUserObject];
        
        imageCache_ = [[TKImageCache alloc] initWithCacheDirectoryName:@"image"];
        imageCache_.notificationName = @"product_detail_image";
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(product_detail_image:) name:@"product_detail_image" object:nil];

    }
    
    return self;
}

- (void)dealloc{
    [imageCache_ cancelOperations];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
    [b setImage:[UIImage imageNamed:@"backhome.png"] forState:UIControlStateNormal];
    b.frame = CGRectMake(10, 10, [UIImage imageNamed:@"backhome.png"].size.width, [UIImage imageNamed:@"backhome.png"].size.height);
    [b addTarget:self action:@selector(ret) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithCustomView:b];
    self.navigationItem.leftBarButtonItem = left;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(search:) name:@"search" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismiss:) name:@"dismiss" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(index1:) name:@"index1" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(coderefresh:) name:@"coderefresh" object:nil];
    
    countnumber = 0;
    similarcountnumber = 0;
    
    totalnum1 = 0;
    isclick = NO;
    ShopObject *shopobj = [shop objectAtIndex:0];
    numshopid = shopobj.shopID;
    
    shopidarray = [[NSMutableArray alloc]init];
    order = [[DataManager sharedManager]createOrderByProduct:obj ShopId:numshopid];
    
    totalnum = [[DataManager sharedManager]getOrderAmountWithCode:obj Shopid:numshopid];
    
    orders = [[NSMutableArray alloc]init];
    bigorders = [[NSMutableArray alloc]init];
    jkorders = [[NSMutableArray alloc]init];
    self.view.backgroundColor = [UIColor colorWithRed:255/255.0 green:250/255.0 blue:232/255.0 alpha:1];
    
#ifdef DHH_iOS
    UIButton *save = [UIButton buttonWithType:UIButtonTypeCustom];
    [save setImage:[UIImage imageNamed:@"detail_save.png"] forState:UIControlStateNormal];
    save.frame = CGRectMake(10, 10, [UIImage imageNamed:@"detail_save.png"].size.width, [UIImage imageNamed:@"detail_save.png"].size.height);
    [save addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *r = [[UIBarButtonItem alloc] initWithCustomView:save];
    self.navigationItem.rightBarButtonItem = r;
    
    
    [self iphoneUI:[user.shopID objectAtIndex:0]
          shopname:user.userName];
#else
    [self ipadUI:obj shopid:numshopid shopname:shopobj.shopName tag:0];
#endif
   // scroll.contentInset = UIEdgeInsetsMake(0, 0, 0, 200);
}
-(void)iphoneUI:(NSString *)shopid shopname:(NSString *)shopname
{
 
    
    UIImageView *back = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"back.png"]];
    back.frame = CGRectMake(0, 0, [UIImage imageNamed:@"back.png"].size.width, [UIImage imageNamed:@"back.png"].size.height);
    [self.view addSubview:back];
    
    UIImage *tintImage = [[UIHelper getInstance] getBundleImage:@"detail_tint.png"];
    tintImage = [tintImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
    
    tint = [[UIImageView alloc]initWithImage:tintImage];
    tint.width = 1024;

    tint.userInteractionEnabled = YES;
    [self.view addSubview:tint];
    
    UIImageView *search = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail_codesearch.png"]];
    search.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_codesearch.png"].size.width, [UIImage imageNamed:@"detail_codesearch.png"].size.height);
    search.center = CGPointMake(820, tint.height/2);
    [self.view addSubview:search];
    
    UIButton *btn = [[UIHelper getInstance] createButtonByFrame:CGRectMake(0, 0, 100, tint.height)];
    [btn setImage:[UIImage imageNamed:@"order_next.png"] forState:UIControlStateNormal];
    [tint addSubview:btn];
    [btn setBackgroundColor:[UIColor clearColor]];
    [btn setTitle:shopname forState:UIControlStateNormal];
    
    /*
     if (shop.count>0) {
     ShopObject *shop1 = [shop objectAtIndex:0];
     [btn setTitle:shop1.shopName forState:UIControlStateNormal];
     }
     */
    
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    //  b.backgroundColor = [[UIHelper getInstance] getRandomColor];
    // b.left = (b.width+30)*i;
    [btn addTarget:self action:@selector(keyClicked:) forControlEvents:UIControlEventTouchUpInside];
    btn.tag = 10;
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 90, 0, 0);
    
    scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    scrollview.bounces = NO;
    scrollview.top = tint.bottom;
    [self.view addSubview:scrollview];
    
    view = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)];
    view.userInteractionEnabled = YES;
    view.top = tint.bottom;
    [scrollview addSubview:view];
    
    iphonescroll = [[UIScrollView alloc]initWithFrame:CGRectMake(10, -35, 300, 380)];
    scrollview.bounces = NO;
    [view addSubview:iphonescroll];
    
    UIView *report = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 152, 35)];
    report.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
    [iphonescroll addSubview:report];
    
    UIView *reportline1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 152, 35)];
    reportline1.backgroundColor = [UIColor whiteColor];
    reportline1.top = report.bottom;
    [iphonescroll addSubview:reportline1];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(75, 0, 1, 70)];
    line.backgroundColor = [UIColor blackColor];
    [iphonescroll addSubview:line];
    
    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(152, 0, 1, 70)];
    line2.backgroundColor = [UIColor blackColor];
    [iphonescroll addSubview:line2];
    
    similar = [[DataManager sharedManager] getSimiliarProduct:obj];
    sizegroupid = [[DataManager sharedManager] getSizeListBySizeGroup:obj.pSizeGroupID SizeType:@""];
    for (int i = 0; i<sizegroupid.count; i++) {
        
        SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(152+77*i+1, 0, 76, 35)];
        label.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
        label.text = sizeobject.sSizeName;
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        [iphonescroll addSubview:label];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(152+77*(i+1), 0, 1, 70)];
        line.backgroundColor = [UIColor blackColor];
        [iphonescroll addSubview:line];
        
        iphonescroll.contentSize = CGSizeMake(152+77*(i+1), 70);
        right = 152 + 77*(i+1);
    }
    
    UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(801, 0, 199, 35)];
    report1.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
    report1.left = right+1;
    [iphonescroll addSubview:report1];
    
    UIView *reportline11 = [[UIView alloc]initWithFrame:CGRectMake(801, 105, 199, 35)];
    reportline11.backgroundColor = [UIColor whiteColor];
    reportline11.left = right+1;
    reportline11.top = report1.bottom;
    [iphonescroll addSubview:reportline11];
    
    UILabel *count = [[UILabel alloc]initWithFrame:CGRectMake(810, 0, 77, 35)];
    count.backgroundColor = [UIColor clearColor];
    count.left = right + 10;
    count.text = @"小计";
    count.textColor = [UIColor whiteColor];
    count.textAlignment = NSTextAlignmentCenter;
    [iphonescroll addSubview:count];
    
    UILabel *operate = [[UILabel alloc]initWithFrame:CGRectMake(890, 0, 77, 35)];
    operate.backgroundColor = [UIColor clearColor];
    operate.left = right + 90;
    operate.text = @"操作";
    operate.textColor = [UIColor whiteColor];
    operate.textAlignment = NSTextAlignmentCenter;
    [iphonescroll addSubview:operate];
    
    UILabel *code = [[UILabel alloc]initWithFrame:CGRectMake(0, 35, 75, 35)];
    code.backgroundColor = [UIColor clearColor];
    NSString *str = [NSString stringWithFormat:@"%@",obj.pColorCode];
    code.text = str;
    code.textAlignment = NSTextAlignmentCenter;
    [iphonescroll addSubview:code];
    
    UILabel *color1 = [[UILabel alloc]initWithFrame:CGRectMake(75, 35, 75, 35)];
    color1.backgroundColor = [UIColor clearColor];
    color1.text = obj.pColor;
    color1.textAlignment = NSTextAlignmentCenter;
    [iphonescroll addSubview:color1];
    
    UIView *reportline2 = [[UIView alloc]initWithFrame:CGRectMake(0, 70, 980, 20)];
    reportline2.backgroundColor = [UIColor yellowColor];
    reportline2.width = right + 200;
    reportline2.top = reportline1.bottom;
    [iphonescroll addSubview:reportline2];
    
    iphonescroll.contentSize = CGSizeMake(right+200, 90);
    
    for(int i=0;i<sizegroupid.count;i++)
    {
        SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
        NSString * sizeno = sizeobject.sSizeNo;
        UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(153+ 77*i, 35, 76, 35)];
        textfield.backgroundColor = [UIColor whiteColor];
        textfield.delegate = self;
        NSString *num = [NSString stringWithFormat:@"%d",[order getOrder:sizeno withShopID:shopid]];
        textfield.text = num;
        textfield.tag = i+10;
        textfield.textAlignment = NSTextAlignmentCenter;
        textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [iphonescroll addSubview:textfield];
        countnumber += [order getOrder:sizeno withShopID:shopid];
    }
    UILabel *countnum = [[UILabel alloc]initWithFrame:CGRectMake(810, 35, 77, 35)];
    countnum.backgroundColor = [UIColor clearColor];
    countnum.left = right + 10;
    countnum.tag = 110000;
    NSString *number = [NSString stringWithFormat:@"%d",countnumber];
    countnum.text = number;
    countnum.textAlignment = NSTextAlignmentCenter;
    [iphonescroll addSubview:countnum];
    
    if (numtag==0) {
        UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
        UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
        [match setBackgroundImage:img3 forState:UIControlStateNormal];
        match.frame = CGRectMake(875, 40, 100, 20);
        match.left = right + 70;
        [match setTitle:@"搭配" forState:UIControlStateNormal];
        [iphonescroll addSubview:match];
        

        UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
        [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
        proportion.frame = CGRectMake(930, 40, 50, 25);
        [proportion setTitle:@"清除" forState:UIControlStateNormal];
        [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
        
        proportion.left = match.right + 10;
        // [proportion setTitle:@"配比" forState:UIControlStateNormal];
        [iphonescroll addSubview:proportion];
    }
    
    else
    {
        UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
        [proportion setImage:[UIImage imageNamed:@"detail_peibi.png"] forState:UIControlStateNormal];
        proportion.frame = CGRectMake(910, 40, [UIImage imageNamed:@"detail_peibi.png"].size.width, [UIImage imageNamed:@"detail_peibi.png"].size.height);
        // [proportion setTitle:@"配比" forState:UIControlStateNormal];
        [iphonescroll addSubview:proportion];
    }
    
    for (int i = 0; i<similar.count; i++) {
        ProductObject *product = [similar objectAtIndex:i];
        OrderObject *orderobj = [[DataManager sharedManager]createOrderByProduct:product ShopId:shopid];
        [orders addObject:orderobj];
        OrderObject *order1 = [orders objectAtIndex:i];
        
        UIView *report = [[UIView alloc]initWithFrame:CGRectMake(0, 90+35*i, 152, 35)];
        report.backgroundColor = [UIColor whiteColor];
        [iphonescroll addSubview:report];
        
        UIView *line11 = [[UIView alloc]initWithFrame:CGRectMake(75, 0, 1, 35)];
        line11.backgroundColor = [UIColor blackColor];
        line11.top = report.top;
        [iphonescroll addSubview:line11];
        
        UIView *line12 = [[UIView alloc]initWithFrame:CGRectMake(152, 0, 1, 35)];
        line12.backgroundColor = [UIColor blackColor];
        line12.top = report.top;
        [iphonescroll addSubview:line12];
        
        UILabel *code = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 75, 35)];
        code.backgroundColor = [UIColor clearColor];
        NSString *str = [NSString stringWithFormat:@"%@",product.pColorCode];
        code.text = str;
        code.textAlignment = NSTextAlignmentCenter;
        code.top = report.top;
        [iphonescroll addSubview:code];
        
        UILabel *color1 = [[UILabel alloc]initWithFrame:CGRectMake(75, 105, 75, 35)];
        color1.backgroundColor = [UIColor clearColor];
        color1.text = product.pColor;
        color1.top = report.top;
        color1.textAlignment = NSTextAlignmentCenter;
        [iphonescroll addSubview:color1];
        
        for(int j=0;j<sizegroupid.count;j++)
        {
            SizeObject *sizeobject = [sizegroupid objectAtIndex:j];
            NSString * sizeno = sizeobject.sSizeNo ;
            UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(153 + 77*j, 0, 76, 35)];
            textfield.backgroundColor = [UIColor whiteColor];
            textfield.delegate = self;
            NSString *num = [NSString stringWithFormat:@"%d",[order1 getOrder:sizeno withShopID:shopid]];
            textfield.text = num;
            textfield.tag = j+100*(i+1);
            textfield.top = report.top;
            textfield.textAlignment = NSTextAlignmentCenter;
            textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            [iphonescroll addSubview:textfield];
            similarcountnumber += [order1 getOrder:sizeno withShopID:shopid];
        }
        iphonescroll.contentSize = CGSizeMake(iphonescroll.contentSize.width, 95+((i+1)*35));
        for (int j = 0; j<sizegroupid.count; j++) {
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(152+77*(j+1), 0, 1, 35)];
            line.backgroundColor = [UIColor blackColor];
            line.top = report.top;
            [iphonescroll addSubview:line];
            
        }
        UIView *scrollline1 = [[UIView alloc]initWithFrame:CGRectMake(152, 0, 77*(sizegroupid.count), 1)];
        scrollline1.backgroundColor = [UIColor blackColor];
        scrollline1.top = report.bottom-1;
        [iphonescroll addSubview:scrollline1];
        
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(800, 0, 1, 35)];
        line1.backgroundColor = [UIColor blackColor];
        line1.top = report.top;
        line1.left = right;
        [iphonescroll addSubview:line1];
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0, line1.bottom, 152, 1)];
        line2.backgroundColor = [UIColor blackColor];
        line2.top = report.bottom-1;
        [iphonescroll addSubview:line2];
        
        UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(801, 90+i*35, 199, 35)];
        report1.backgroundColor = [UIColor whiteColor];
        report1.left = right + 1;
        [iphonescroll addSubview:report1];
        
        UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(801, line1.bottom, 199, 1)];
        line3.backgroundColor = [UIColor blackColor];
        line3.top = report1.bottom-1;
        line3.left = right + 1;
        [iphonescroll addSubview:line3];
        
        UILabel *countnumone = [[UILabel alloc]initWithFrame:CGRectMake(810, 90+i*35, 77, 35)];
        countnumone.backgroundColor = [UIColor clearColor];
        countnumone.left = right + 10;
        countnumone.tag = 110001+i;
        NSString *number = [NSString stringWithFormat:@"%d",similarcountnumber];
        countnumone.text = number;
        countnumone.textAlignment = NSTextAlignmentCenter;
        [iphonescroll addSubview:countnumone];
        
        if (numtag==0) {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
            [match setBackgroundImage:img3 forState:UIControlStateNormal];
            match.frame = CGRectMake(875, 95+35*i, 50, 25);
            match.tag = 100001+i;
            [match setTitle:@"搭配" forState:UIControlStateNormal];
            [match addTarget:self action:@selector(suit:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:match];
            
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(930, 95+35*i, 50, 25);
            proportion.left = right + 110;
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            //  [proportion setTitle:@"配比" forState:UIControlStateNormal];
            [iphonescroll addSubview:proportion];
        }
        else
        {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(930, 95+35*i, 50, 25);
             [proportion setTitle:@"清除" forState:UIControlStateNormal];
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            proportion.left = right + 110;
            //  [proportion setTitle:@"配比" forState:UIControlStateNormal];
            [iphonescroll addSubview:proportion];
        }
    }
    scrollview.contentSize = CGSizeMake(self.view.width, iphonescroll.contentSize.height);
    
    detail = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail.png"]];
    detail.frame = CGRectMake(10, 360, 300, 260);
    detail.top = iphonescroll.contentSize.height+20;
    [scrollview addSubview:detail];
    
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(10, 26, 250, 23)];
    name.backgroundColor = [UIColor clearColor];
    name.font = [UIFont systemFontOfSize:14];
    name.textColor = [UIColor whiteColor];
    NSString *namestr = [NSString stringWithFormat:@"商品名称：%@",obj.pName];
    name.text = namestr;
    [detail addSubview:name];
    
    UILabel *color = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    color.backgroundColor = [UIColor clearColor];
    color.font = [UIFont systemFontOfSize:14];
    color.textColor = [UIColor whiteColor];
    NSString *colorstr = [NSString stringWithFormat:@"商品颜色：%@",obj.pColor];
    color.text = colorstr;
    color.top = name.bottom;
    [detail addSubview:color];
    
    UILabel *sex = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    sex.backgroundColor = [UIColor clearColor];
    sex.font = [UIFont systemFontOfSize:14];
    sex.textColor = [UIColor whiteColor];
    sex.text = @"性别：";
    sex.top = color.bottom;
    [detail addSubview:sex];
    
    UILabel *coat = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    coat.backgroundColor = [UIColor clearColor];
    coat.font = [UIFont systemFontOfSize:14];
    coat.textColor = [UIColor whiteColor];
    coat.text = @"上下装：";
    coat.top = sex.bottom+1;
    [detail addSubview:coat];
    
    UILabel *system = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    system.backgroundColor = [UIColor clearColor];
    system.font = [UIFont systemFontOfSize:14];
    system.textColor = [UIColor whiteColor];
    NSString *systemstr = [NSString stringWithFormat:@"系列：%@",obj.pSerial];
    system.text = systemstr;
    system.top = coat.bottom;
    [detail addSubview:system];
    
    UILabel *date = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    date.backgroundColor = [UIColor clearColor];
    date.font = [UIFont systemFontOfSize:14];
    date.textColor = [UIColor whiteColor];
    date.text = @"上市波段：";
    date.top = system.bottom;
    [detail addSubview:date];
    
    UILabel *size = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    size.backgroundColor = [UIColor clearColor];
    size.font = [UIFont systemFontOfSize:14];
    size.textColor = [UIColor whiteColor];
    size.text = @"版型：";
    size.top = date.bottom;
    [detail addSubview:size];
    
    UILabel *price = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    price.backgroundColor = [UIColor clearColor];
    price.font = [UIFont systemFontOfSize:14];
    price.textColor = [UIColor whiteColor];
    NSString *pricestr = [NSString stringWithFormat:@"价格段：￥%.0f",obj.pSale];
    price.text = pricestr;
    price.top = size.bottom+1;
    [detail addSubview:price];
    
    UILabel *texture = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 350, 23)];
    texture.backgroundColor = [UIColor clearColor];
    texture.font = [UIFont systemFontOfSize:14];
    texture.textColor = [UIColor whiteColor];
    if(obj.pNote)
    {
        NSString *texturestr = [NSString stringWithFormat:@"面料：%@",obj.pNote];
        texture.text = texturestr;
    }
    else
    {
        texture.text = @"面料:";
    }
    texture.top = price.bottom;
    [detail addSubview:texture];
    
    UILabel *season = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 23)];
    season.backgroundColor = [UIColor clearColor];
    season.font = [UIFont systemFontOfSize:14];
    season.textColor = [UIColor whiteColor];
    if(obj.pSeason)
    {
        NSString *seasonstr = [NSString stringWithFormat:@"季节：%@",obj.pSeason];
        season.text = seasonstr;
    }
    else
    {
        season.text = @"季节:";
    }
    season.top = texture.bottom;
    [detail addSubview:season];
    
    scrollview.contentSize = CGSizeMake(self.view.width, scrollview.contentSize.height + detail.height+150);
    
    UIImage *img = [UIImage imageNamed:@"coatimage.png"];
    UIImageView *coatimage = [[UIImageView alloc]initWithImage:img];
    coatimage.userInteractionEnabled = YES;
    
    UIView *container = [[UIView alloc] initWithFrame:coatimage.bounds];
    [scrollview addSubview:container];
    container.top = detail.bottom+5;
    container.centerX = self.view.width/2;
    
    UIImageView *productImageV = [[UIImageView alloc] initWithFrame:CGRectMake(13, 17, 272, 266)];
   // [container addSubview:productImageV];
    productImageV.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [productImageV addGestureRecognizer:tapGes];
    productImageV.backgroundColor = [UIColor clearColor];
    
    UIImage *img1 = [UIImage imageNamed:@"collect_back.png"];
    UIImageView *collectback = [[UIImageView alloc]initWithImage:img1];
    collectback.frame = CGRectMake(0, 0, img1.size.width, img1.size.height);
    collectback.right = productImageV.right;
    collectback.bottom = productImageV.bottom-3;
    [coatimage addSubview:collectback];
    
    productImage_ = productImageV;
    NSString *url = [NSString stringWithFormat:@"_%@",obj.pThumbURL];
    NSString * path = [[[PMGlobal getInstance] getImageURL] stringByAppendingPathComponent:url];
    productImage_.image = [imageCache_ imageForKey:obj.pThumbURL url:[NSURL URLWithString:path] queueIfNeeded:YES tag:0];
    
    UIImage *img2 = [UIImage imageNamed:@"collect_image.png"];
    for (int i = 0; i<5; i++) {
        UIButton *collect = [UIButton buttonWithType:UIButtonTypeCustom];
        if (i<[[DataManager sharedManager]productIsFavorite:obj Shopid:nil]) {
            [collect setBackgroundImage:[UIImage imageNamed:@"collect_redimage.png"] forState:UIControlStateNormal];
        }
        else
        {
            [collect setBackgroundImage:img2 forState:UIControlStateNormal];
        }
        collect.frame = CGRectMake(i*52+28, 0, img2.size.width, img2.size.height);
        collect.tag = i+10000;
        // collect.right = productImageV.right-5;
        collect.bottom = productImageV.bottom-15;
        [collect addTarget:self action:@selector(collect:) forControlEvents:UIControlEventTouchUpInside];
        [coatimage addSubview:collect];
    }

    
    coatimage.frame = CGRectMake(0, 0, img.size.width, img.size.height);
    [container addSubview:coatimage];
    
    sale = [[UILabel alloc]initWithFrame:CGRectMake(25, 293, 100, 30)];
    sale.backgroundColor = [UIColor clearColor];
    sale.textColor = [UIColor whiteColor];
    NSString *salestr = [NSString stringWithFormat:@"￥%.0f",obj.pSale];
    sale.text = salestr;
    [coatimage addSubview:sale];
    
    code1 = [[UILabel alloc]initWithFrame:CGRectMake(130, 293, 100, 30)];
    code1.backgroundColor = [UIColor clearColor];
    code1.textColor = [UIColor blackColor];
    code1.text = obj.pCode;
    code1.textAlignment = NSTextAlignmentCenter;
    code1.centerX = 150;
    [coatimage addSubview:code1];
    
    scrollview.contentSize = CGSizeMake(self.view.width, scrollview.contentSize.height + container.height);
}


-(void)ipadUI:(ProductObject *)product shopid:(NSString *)shopid shopname:(NSString *)shopname tag:(int)tag
{
    
    [self.view removeAllSubviews];
    countnumber = 0;
    similarcountnumber = 0;
    bigobj = [[DataManager sharedManager]getProduct:[obj.pCode stringByAppendingString:@"K"]withColorID:[NSString stringWithFormat:@"%@", product.pColorCode]];
    jkobj = [[DataManager sharedManager]getProduct:[obj.pCode stringByAppendingString:@"JK"]withColorID:[NSString stringWithFormat:@"%@", product.pColorCode]];
    if (bigobj) {
        bigorder = [[DataManager sharedManager]createOrderByProduct:bigobj ShopId:numshopid];
    }
    if (jkobj) {
        jkorder = [[DataManager sharedManager]createOrderByProduct:jkobj ShopId:numshopid];
    }
    /*
    UIImageView *back = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"back.png"]];
    back.frame = CGRectMake(0, 0, [UIImage imageNamed:@"back.png"].size.width, [UIImage imageNamed:@"back.png"].size.height);
    [self.view addSubview:back];
     */
    
    UIImage *tintImage = [[UIHelper getInstance] getBundleImage:@"detail_tint.png"];
    tintImage = [tintImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
    
    tint = [[UIImageView alloc]initWithImage:tintImage];
    tint.width = 1024;

    tint.userInteractionEnabled = YES;
    [self.view addSubview:tint];
    /*
   */
    
    UIImageView *search = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail_codesearch.png"]];
    search.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_codesearch.png"].size.width, [UIImage imageNamed:@"detail_codesearch.png"].size.height);
    search.center = CGPointMake(820, tint.height/2);
    [tint addSubview:search];
    
    view = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 1024, 230)];
    view.userInteractionEnabled = YES;
    view.bounces = NO;
    view.top = tint.bottom+30;
    [self.view addSubview:view];
    
    UIButton *copy = [UIButton buttonWithType:UIButtonTypeCustom];
    [copy setImage:[UIImage imageNamed:@"detail_copy.png"] forState:UIControlStateNormal];
    copy.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_copy.png"].size.width, [UIImage imageNamed:@"detail_copy.png"].size.height);
    copy.center = CGPointMake(680, tint.height/2);
    [copy addTarget:self action:@selector(copy1) forControlEvents:UIControlEventTouchUpInside];
  //  [tint addSubview:copy];
    
    UIButton *select = [UIButton buttonWithType:UIButtonTypeCustom];
    select.frame = CGRectMake(0, 0, 100, 30);
    [select setBackgroundImage:[UIImage imageNamed:@"anniu.png"] forState:UIControlStateNormal];
    [select setTitle:@"切换代码" forState:UIControlStateNormal];
    select.center = CGPointMake(960, tint.height/2);
    [select addTarget:self action:@selector(selectcode) forControlEvents:UIControlEventTouchUpInside];
    [tint addSubview:select];
    
    codesearch = [[UITextField alloc]initWithFrame:CGRectMake(780, 12, 100, 20)];
    codesearch.backgroundColor = [UIColor clearColor];
    codesearch.inputView = [[UIView alloc]initWithFrame:CGRectZero];
    codesearch.delegate = self;
    codesearch.tag = 1000;
<<<<<<< .merge_file_Yw9D9p
    if (isclick == YES) {
        codesearch.placeholder = @"模糊搜索";
    }
    else
    {
    codesearch.placeholder = @"简码搜索";
=======
    if (isclick) {
        codesearch.placeholder = @"模糊搜索";
    }
    else{
        codesearch.placeholder = @"简码搜索";
>>>>>>> .merge_file_hF630f
    }
    codesearch.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    [tint addSubview:codesearch];
    
 
    //暂时先屏蔽多店铺选择
//    UIButton *btn = [[UIHelper getInstance] createButtonByFrame:CGRectMake(0, 0, 100, tint.height)];
//    [btn setImage:[UIImage imageNamed:@"order_next.png"] forState:UIControlStateNormal];
//    [tint addSubview:btn];
//    [btn setBackgroundColor:[UIColor clearColor]];
//    [btn setTitle:user.userName forState:UIControlStateNormal];
    
    /*
     if (shop.count>0) {
     ShopObject *shop1 = [shop objectAtIndex:0];
     [btn setTitle:shop1.shopName forState:UIControlStateNormal];
     }
     */
    
//    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    //  b.backgroundColor = [[UIHelper getInstance] getRandomColor];
    // b.left = (b.width+30)*i;
//    [btn addTarget:self action:@selector(keyClicked:) forControlEvents:UIControlEventTouchUpInside];
//    btn.tag = 10;
//    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 90, 0, 0);
//    
    
    UIView *report = [[UIView alloc]initWithFrame:CGRectMake(20, 0, 152, 35)];
    report.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
    [view addSubview:report];
    
    UIView *reportline1 = [[UIView alloc]initWithFrame:CGRectMake(20, 0, 152, 35)];
    reportline1.backgroundColor = [UIColor whiteColor];
    reportline1.top = report.bottom;
    [view addSubview:reportline1];
    
    UIView *reportline2 = [[UIView alloc]initWithFrame:CGRectMake(20, 0, 980, 20)];
    reportline2.backgroundColor = [UIColor yellowColor];
    reportline2.top = reportline1.bottom;
    [view addSubview:reportline2];
    
    self.scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(172, 0, 630, view.height+200)];
    self.scroll.alwaysBounceVertical = NO;
    self.scroll.alwaysBounceHorizontal = YES;
    self.scroll.showsHorizontalScrollIndicator = NO;
    self.scroll.bounces = NO;
    [view addSubview:self.scroll];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(95, 0, 1, 70)];
    line.backgroundColor = [UIColor blackColor];
    [view addSubview:line];
    
    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(172, 0, 1, 70)];
    line2.backgroundColor = [UIColor blackColor];
    [view addSubview:line2];
    
    similar = [[DataManager sharedManager] getSimiliarProduct:obj];
    
    
    //获取有几种板式，普通的为一种，西装有3种A、B、C
    sizeType = [[DataManager sharedManager] getSizeTypeBySizeGroup:obj.pSizeGroupID];
    
    for (int i=0;i<sizeType.count;i++) {
        
        if (![[sizeType objectAtIndex:i] isEqualToString:@""]) {
            UIButton *typeAbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            typeAbtn.frame = CGRectMake(0, 0, 80, 25);
            [typeAbtn setBackgroundImage:[UIImage imageNamed:@"anniu.png"] forState:UIControlStateNormal];
            [typeAbtn setTitle:[sizeType objectAtIndex:i] forState:UIControlStateNormal];
            typeAbtn.origin = CGPointMake(i*85+20, 0);
            [typeAbtn addTarget:self action:@selector(selectSizeType:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:typeAbtn];
            typeAbtn.top = tint.bottom+5;
            typeAbtn.tag = 1100+i;
        }
    }
    
    sizegroupid = [[DataManager sharedManager] getSizeListBySizeGroup:obj.pSizeGroupID SizeType:[sizeType objectAtIndex:0]];
    
    
    for (int i = 0; i<sizegroupid.count; i++) {
        
        SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
        if (sizegroupid.count<10) {
            width = self.scroll.width/sizegroupid.count;
        }
        else
        {
            width = 70;
        }
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(width*i+1, 0, width-1, 35)];
        label.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
        label.text = sizeobject.sSizeName;
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.tag = 1500+i;
        [self.scroll addSubview:label];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(width*(i+1), 0, 1, 70)];
        line.backgroundColor = [UIColor blackColor];
        [self.scroll addSubview:line];
        
        self.scroll.contentSize = CGSizeMake(width*(i+1), 70);
    }
    UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 70)];
    line1.backgroundColor = [UIColor blackColor];
    [view addSubview:line1];
    
    UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(803, 0, 199, 35)];
    report1.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
    [view addSubview:report1];
    
    UIView *reportline11 = [[UIView alloc]initWithFrame:CGRectMake(803, 0, 199, 35)];
    reportline11.backgroundColor = [UIColor whiteColor];
    reportline11.top = report1.bottom;
    [view addSubview:reportline11];
    
    UILabel *count = [[UILabel alloc]initWithFrame:CGRectMake(812, 0, 77, 35)];
    count.backgroundColor = [UIColor clearColor];
    count.text = @"小计";
    count.textColor = [UIColor whiteColor];
    count.textAlignment = NSTextAlignmentCenter;
    [view addSubview:count];
    
    UILabel *operate = [[UILabel alloc]initWithFrame:CGRectMake(892, 0, 77, 35)];
    operate.backgroundColor = [UIColor clearColor];
    operate.text = @"操作";
    operate.textColor = [UIColor whiteColor];
    operate.textAlignment = NSTextAlignmentCenter;
    [view addSubview:operate];
    
    //产品订单信息
    UILabel *code = [[UILabel alloc]initWithFrame:CGRectMake(20, 35, 75, 35)];
    code.backgroundColor = [UIColor clearColor];
    if ([obj.pCode hasSuffix:@"K"]&& ![obj.pCode hasSuffix:@"JK"]) {
        code.text = [NSString stringWithFormat:@"%@(加大）",obj.pColorCode];
    }
    else{
        code.text = [NSString stringWithFormat:@"%@",obj.pColorCode];
    }
    
       code.textAlignment = NSTextAlignmentCenter;
    [view addSubview:code];
    
    UILabel *color1 = [[UILabel alloc]initWithFrame:CGRectMake(95, 35, 75, 35)];
    color1.backgroundColor = [UIColor clearColor];
    color1.text = obj.pColor;
    color1.textAlignment = NSTextAlignmentCenter;
    [view addSubview:color1];
    
    
    UIView* dummyView = [[UIView alloc] initWithFrame:CGRectZero];
    for(int i=0;i<sizegroupid.count;i++)
    {
        SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
        UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(1+ width*i, 35, width-1, 35)];
        textfield.backgroundColor = [UIColor whiteColor];
        textfield.delegate = self;
        NSString *num = [NSString stringWithFormat:@"%d",[order getOrder:sizeobject.sSizeNo withShopID:numshopid]];
        textfield.text = num;
        textfield.tag = i+10;
        textfield.inputView = dummyView;
        textfield.textAlignment = NSTextAlignmentCenter;
        textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [self.scroll addSubview:textfield];
        countnumber += [order getOrder:sizeobject.sSizeNo withShopID:numshopid];
    }
    UILabel *countnum = [[UILabel alloc]initWithFrame:CGRectMake(812, 35, 77, 35)];
    countnum.backgroundColor = [UIColor clearColor];
    NSString *number = [NSString stringWithFormat:@"%d",countnumber];
    countnum.text = number;
    countnum.tag = 110000;
    countnum.textAlignment = NSTextAlignmentCenter;
    [view addSubview:countnum];
    
    if (numtag==0) {
        UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
        UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
        [match setBackgroundImage:img3 forState:UIControlStateNormal];
        match.frame = CGRectMake(875, 40, 50, 25);
        match.tag = 100000;
        [match setTitle:@"搭配" forState:UIControlStateNormal];
        [match addTarget:self action:@selector(suit:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:match];
        
        UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
        [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
        proportion.frame = CGRectMake(930, 40, 50, 25);
        [proportion setTitle:@"清除" forState:UIControlStateNormal];
        [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
        proportion.tag = 20000;
        // [proportion setTitle:@"配比" forState:UIControlStateNormal];
        [view addSubview:proportion];
    }
    else
    {
        UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
        UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
        [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
        proportion.frame = CGRectMake(910, 40, 50, 25);
        [proportion setTitle:@"清除" forState:UIControlStateNormal];
        [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
        // [proportion setTitle:@"配比" forState:UIControlStateNormal];
        [view addSubview:proportion];
        proportion.tag = 20000;
    }
    
    
    //同款不同色
    for (int i = 0; i<similar.count; i++) {
        similarcountnumber = 0;
        ProductObject *product = [similar objectAtIndex:i];
        OrderObject *orderobj = [[DataManager sharedManager]createOrderByProduct:product ShopId:shopid];
        [orders addObject:orderobj];
        OrderObject *order1 = [orders objectAtIndex:i];
        
        UIView *report = [[UIView alloc]initWithFrame:CGRectMake(20, 35*i+reportline2.bottom, 152, 35)];
        report.backgroundColor = [UIColor whiteColor];
        [view addSubview:report];
        
        UIView *line11 = [[UIView alloc]initWithFrame:CGRectMake(95, 0, 1, 35)];
        line11.backgroundColor = [UIColor blackColor];
        line11.top = report.top;
        [view addSubview:line11];
        
        UIView *line12 = [[UIView alloc]initWithFrame:CGRectMake(172, 0, 1, 35)];
        line12.backgroundColor = [UIColor blackColor];
        line12.top = report.top;
        [view addSubview:line12];
        
        UILabel *code = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 75, 35)];
        code.backgroundColor = [UIColor clearColor];
        NSString *str = product.pColorCode;
        if ([[product.pCode uppercaseString] hasSuffix:@"K"]) {
            str = [NSString stringWithFormat:@"%@(加大)",product.pColorCode];
        }
        
        
        code.text = str;
        code.textAlignment = NSTextAlignmentCenter;
        code.top = report.top;
        [view addSubview:code];
        
        UILabel *color1 = [[UILabel alloc]initWithFrame:CGRectMake(95, 35, 75, 35)];
        color1.backgroundColor = [UIColor clearColor];
        color1.text = product.pColor;
        color1.top = report.top;
        color1.textAlignment = NSTextAlignmentCenter;
        [view addSubview:color1];
        
        for(int j=0;j<sizegroupid.count;j++)
        {
            SizeObject *sizeobject = [sizegroupid objectAtIndex:j];
            NSString * sizeno = sizeobject.sSizeNo ;
            UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(1 + width*j, 0, width-1, 35)];
            textfield.backgroundColor = [UIColor whiteColor];
            textfield.delegate = self;
            NSString *num = [NSString stringWithFormat:@"%d",[order1 getOrder:sizeno withShopID:numshopid]];
            textfield.text = num;
            textfield.tag = j+100*(i+1);
            textfield.top = report.top;
            textfield.inputView = dummyView;
            textfield.textAlignment = NSTextAlignmentCenter;
            textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            [self.scroll addSubview:textfield];
            similarcountnumber += [order1 getOrder:sizeno withShopID:numshopid];
        }
        self.scroll.contentSize = CGSizeMake(self.scroll.contentSize.width, 95+(i*35));
        for (int j = 0; j<sizegroupid.count; j++) {
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(width*(j+1), 0, 1, 35)];
            line.backgroundColor = [UIColor blackColor];
            line.top = report.top;
            [self.scroll addSubview:line];
            
        }
        UIView *scrollline = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 35)];
        scrollline.backgroundColor = [UIColor blackColor];
        scrollline.top = report.top;
        [view addSubview:scrollline];
        
        UIView *scrollline1 = [[UIView alloc]initWithFrame:CGRectMake(0, line1.bottom, width*(sizegroupid.count), 1)];
        scrollline1.backgroundColor = [UIColor blackColor];
        scrollline1.top = report.bottom-1;
        [self.scroll addSubview:scrollline1];
        
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 35)];
        line1.backgroundColor = [UIColor blackColor];
        line1.top = report.top;
        [view addSubview:line1];
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(20, line1.bottom, 152, 1)];
        line2.backgroundColor = [UIColor blackColor];
        line2.top = report.bottom-1;
        [view addSubview:line2];
        
        UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(803, 90+i*35, 199, 35)];
        report1.backgroundColor = [UIColor whiteColor];
        [view addSubview:report1];
        
        UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(803, line1.bottom, 199, 1)];
        line3.backgroundColor = [UIColor blackColor];
        line3.top = report1.bottom-1;
        [view addSubview:line3];
        
        UILabel *countnumone = [[UILabel alloc]initWithFrame:CGRectMake(812, 90+i*35, 77, 35)];
        countnumone.backgroundColor = [UIColor clearColor];
        NSString *number = [NSString stringWithFormat:@"%d",similarcountnumber];
        countnumone.text = number;
        countnumone.textAlignment = NSTextAlignmentCenter;
        countnumone.tag = 110001+i;
        [view addSubview:countnumone];
        
        if (numtag==0) {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
            [match setBackgroundImage:img3 forState:UIControlStateNormal];
            match.frame = CGRectMake(875, 95+35*i, 50, 25);
            match.tag = 100001+i;
            [match setTitle:@"搭配" forState:UIControlStateNormal];
            [match addTarget:self action:@selector(suit:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:match];
            
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(930, 95+35*i, 50, 25);
            [proportion setTitle:@"清除" forState:UIControlStateNormal];
            proportion.tag = 21000+i;
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            
            //  [proportion setTitle:@"配比" forState:UIControlStateNormal];
            [view addSubview:proportion];
        }
        else
        {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(910, 95+35*i, 50, 25);
            [proportion setTitle:@"清除" forState:UIControlStateNormal];
            proportion.tag = 21000+i;
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            
            [view addSubview:proportion];
        }
    }
    
        
    //商品信息
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(20, 320, 150, 40)];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor blackColor];
    title.text = @"最小起订量：0件";
    [self.view addSubview:title];
    
    totallabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 320, 150, 40)];
    totallabel.backgroundColor = [UIColor clearColor];
    totallabel.centerX = 512;
    totallabel.textColor = [UIColor blackColor];
    NSString *str = [NSString stringWithFormat:@"订单总量：%d",totalnum];
    totallabel.text = str;
    totallabel.tag = 160000;
    [self.view addSubview:totallabel];
    
    UIButton *save = [UIButton buttonWithType:UIButtonTypeCustom];
    [save setImage:[UIImage imageNamed:@"detail_save.png"] forState:UIControlStateNormal];
    save.frame = CGRectMake(900, 320, [UIImage imageNamed:@"detail_save.png"].size.width, [UIImage imageNamed:@"detail_save.png"].size.height);
    // [save setTitle:@"保存" forState:UIControlStateNormal];
    [save addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:save];
    
    view.contentSize = CGSizeMake(view.width, self.scroll.contentSize.height+80);
    
    UIImageView *background = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail_background.jpg"]];
    background.frame = CGRectMake(0, 360, [UIImage imageNamed:@"detail_background.jpg"].size.width, [UIImage imageNamed:@"detail_background.jpg"].size.width);
    [self.view addSubview:background];
    
    UIImage *img = [UIImage imageNamed:@"coatimage.png"];
    UIImageView *coatimage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"clear.png"]];
    coatimage.frame = CGRectMake(0, 0, img.size.width, img.size.height);
    coatimage.userInteractionEnabled = YES;
    
    UIView *container = [[UIView alloc] initWithFrame:coatimage.bounds];
    [self.view addSubview:container];
    container.userInteractionEnabled = YES;
    container.top = 360;
    
    UIImageView *productImageV = [[UIImageView alloc] initWithFrame:CGRectMake(13, 17, 272, 266)];
    [container addSubview:productImageV];
    productImageV.userInteractionEnabled = YES;
    productImageV.backgroundColor = [UIColor clearColor];
    
    UIImageView *clear = [[UIImageView alloc] initWithFrame:CGRectMake(13, 17, 272, 214)];
    [coatimage addSubview:clear];
    clear.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [clear addGestureRecognizer:tapGes];
    clear.clipsToBounds = YES;
    clear.contentMode = UIViewContentModeScaleAspectFill;
    clear.backgroundColor = [UIColor clearColor];
    productImage_ = productImageV;
    NSString *url = [NSString stringWithFormat:@"%@",obj.pThumbURL];
    NSString * path = [[[PMGlobal getInstance] getImageURL] stringByAppendingPathComponent:url];
    productImage_.image = [imageCache_ imageForKey:obj.pThumbURL url:[NSURL URLWithString:path] queueIfNeeded:YES tag:0];
    
    UIImage *img1 = [UIImage imageNamed:@"collectbar.png"];
    UIImageView *collectback = [[UIImageView alloc]initWithImage:img1];
    collectback.frame = CGRectMake(0, 0, img1.size.width, img1.size.height);
    collectback.right = productImageV.right-1;
    collectback.bottom = productImageV.bottom;
    [coatimage addSubview:collectback];
    
    UIImage *img2 = [UIImage imageNamed:@"collect_image.png"];
    for (int i = 0; i<5; i++) {
    UIButton *collect = [UIButton buttonWithType:UIButtonTypeCustom];
    if (i<[[DataManager sharedManager]productIsFavorite:obj Shopid:nil]) {
        [collect setBackgroundImage:[UIImage imageNamed:@"collect_redimage.png"] forState:UIControlStateNormal];
    }
    else
    {
        [collect setBackgroundImage:img2 forState:UIControlStateNormal];
    }
        collect.frame = CGRectMake(i*52+28, 0, img2.size.width, img2.size.height);
        collect.tag = i+10000;
       // collect.right = productImageV.right-5;
        collect.bottom = productImageV.bottom-15;
        [collect addTarget:self action:@selector(collect:) forControlEvents:UIControlEventTouchUpInside];
        [coatimage addSubview:collect];
    }
    
    collectback.userInteractionEnabled = YES;
    
    
    coatimage.frame = CGRectMake(0, 0, img.size.width, img.size.height);
    [container addSubview:coatimage];
    
    UIImageView *imagebar = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail_coatimagebar.png"]];
    imagebar.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_coatimagebar.png"].size.width, [UIImage imageNamed:@"detail_coatimagebar.png"].size.height);
    imagebar.center = CGPointMake(coatimage.width/2, 310);
    [coatimage addSubview:imagebar];
    
    sale = [[UILabel alloc]initWithFrame:CGRectMake(15, 293, 100, 30)];
    sale.backgroundColor = [UIColor clearColor];
    sale.textColor = [UIColor whiteColor];
    NSString *salestr = [NSString stringWithFormat:@"￥%.0f",obj.pSale];
    sale.text = salestr;
    [coatimage addSubview:sale];
    
    code1 = [[UILabel alloc]initWithFrame:CGRectMake(130, 293, 100, 30)];
    code1.backgroundColor = [UIColor clearColor];
    code1.textColor = [UIColor blackColor];
    code1.text = obj.pCode;
    code1.textAlignment = NSTextAlignmentCenter;
    code1.centerX = 150;
    [coatimage addSubview:code1];
    
    detail = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"clear.png"]];
    detail.frame = CGRectMake(0, 360, [UIImage imageNamed:@"detail.png"].size.width, [UIImage imageNamed:@"detail.png"].size.height);
    detail.userInteractionEnabled = YES;
    detail.left = coatimage.right + 10;
    detailleftnum = detail.left;
    [self.view addSubview:detail];
    
    UILabel *titlecell = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, 30)];
    titlecell.backgroundColor = [UIColor clearColor];
    titlecell.center = CGPointMake(detail.width/2, 15);
    titlecell.text = @"商品详情";
    titlecell.textColor = [UIColor colorWithRed:57/255.0 green:14/255.0 blue:0 alpha:1.0];
    titlecell.textAlignment = NSTextAlignmentCenter;
    [detail addSubview:titlecell];
    
    UIImageView *titleline = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail_titleline.png"]];
    titleline.frame = CGRectMake(0, 0, detail.width, [UIImage imageNamed:@"detail_titleline.png"].size.height);
    titleline.center = CGPointMake(detail.width/2, 34);
    [detail addSubview:titleline];
    
    UIScrollView *detailscroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 35, detail.width, detail.height-35)];
    detailscroll.backgroundColor = [UIColor clearColor];
    detailscroll.clipsToBounds = YES;
    [detail addSubview:detailscroll];
    
    for (int i = 0; i<11; i++) {
        if (i==0) {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"商品编码：%@",obj.pCode];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==1)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"商品名称：%@",obj.pName];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==2)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"大类：%@",obj.pSerial];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==3)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"小类：%@",obj.pType];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==4)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"季节：%@",obj.pSeason];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==5)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"风格：%@",obj.pFengge];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==6)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"系列：%@",obj.pxilie];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==7)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"展厅：%@",obj.pZhanting];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==8)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"吊牌价：￥%.0f",obj.pSale];
            cell.title.text = str;
            [detailscroll addSubview:cell];
        }
        else if(i==9)
        {
            DetailcellView *cell = [[DetailcellView alloc]initWithFrame:CGRectMake(0, 30*i, detail.width, 31)];
            NSString *str = [NSString stringWithFormat:@"版型：%@",obj.pBanxing];
            cell.title.text = str;
            [detailscroll addSubview:cell];
            detailscroll.contentSize = CGSizeMake(detailscroll.width, 30*(i+1));
        }
        else if(i==10)
        {
            UILabel *note = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 300, 30)];
            note.backgroundColor = [UIColor clearColor];
            note.textColor = [UIColor colorWithRed:57/255.0 green:14/255.0 blue:0 alpha:1.0];
            note.top = detailscroll.contentSize.height;
            NSString *notestr = [NSString stringWithFormat:@"成分：%@",obj.pNote];
            CGSize s = [notestr sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(note.width, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
            note.text = notestr;
            note.height = s.height;
            note.numberOfLines = 0;
            [detailscroll addSubview:note];
            
            UIView *noteline = [[UIView alloc]initWithFrame:CGRectMake(0, 0, detail.width, 1)];
            noteline.top = note.bottom;
            noteline.backgroundColor = [UIColor colorWithRed:57/255.0 green:14/255.0 blue:0 alpha:1.0];
            [detailscroll addSubview:noteline];
            
            detailscroll.contentSize = CGSizeMake(detailscroll.width, detailscroll.contentSize.height+s.height+1);
        }
    }
    
    /*
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 250, 30)];
    name.backgroundColor = [UIColor clearColor];
    name.textColor = [UIColor whiteColor];
    NSString *namestr = [NSString stringWithFormat:@"商品名称：%@",obj.pName];
    name.text = namestr;
    [detailscroll addSubview:name];
    
    UIView *nameline = [[UIView alloc]initWithFrame:CGRectMake(0, 0, detail.width, 1)];
    nameline.top = name.bottom;
    nameline.backgroundColor = [UIColor whiteColor];
    [detailscroll addSubview:nameline];
    
    UILabel *color = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 30)];
    color.backgroundColor = [UIColor clearColor];
    color.textColor = [UIColor whiteColor];
    NSString *colorstr = [NSString stringWithFormat:@"商品颜色：%@",obj.pColor];
    color.text = colorstr;
    color.top = name.bottom+1;
    [detailscroll addSubview:color];
    
    UILabel *sex = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 30)];
    sex.backgroundColor = [UIColor clearColor];
    sex.textColor = [UIColor whiteColor];
    sex.text = @"性别：";
    sex.top = color.bottom+1;
    [detailscroll addSubview:sex];
    
    UILabel *coat = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 29)];
    coat.backgroundColor = [UIColor clearColor];
    coat.textColor = [UIColor whiteColor];
    coat.text = @"上下装：";
    coat.top = sex.bottom+1;
    [detailscroll addSubview:coat];
    
    UILabel *system = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 29)];
    system.backgroundColor = [UIColor clearColor];
    system.textColor = [UIColor whiteColor];
    NSString *systemstr = [NSString stringWithFormat:@"系列：%@",obj.pSerial];
    system.text = systemstr;
    system.top = coat.bottom+1;
    [detailscroll addSubview:system];
    
    UILabel *date = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 29)];
    date.backgroundColor = [UIColor clearColor];
    date.textColor = [UIColor whiteColor];
    date.text = @"上市波段：";
    date.top = system.bottom+1;
    [detailscroll addSubview:date];
    
    UILabel *size = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 29)];
    size.backgroundColor = [UIColor clearColor];
    size.textColor = [UIColor whiteColor];
    size.text = @"版型：";
    size.top = date.bottom+1;
    [detailscroll addSubview:size];
    
    UILabel *price = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 30)];
    price.backgroundColor = [UIColor clearColor];
    price.textColor = [UIColor whiteColor];
    NSString *pricestr = [NSString stringWithFormat:@"价格段：￥%.0f",obj.pSale];
    price.text = pricestr;
    price.top = size.bottom+1;
    [detailscroll addSubview:price];
    
    UILabel *texture = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 350, 30)];
    texture.backgroundColor = [UIColor clearColor];
    texture.textColor = [UIColor whiteColor];
    if(obj.pNote)
    {
        NSString *texturestr = [NSString stringWithFormat:@"面料：%@",obj.pNote];
        texture.text = texturestr;
    }
    else
    {
        texture.text = @"面料:";
    }
    texture.top = price.bottom+1;
    [detailscroll addSubview:texture];
    
    UILabel *season = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 200, 30)];
    season.backgroundColor = [UIColor clearColor];
    season.textColor = [UIColor whiteColor];
    if(obj.pSeason)
    {
        NSString *seasonstr = [NSString stringWithFormat:@"季节：%@",obj.pSeason];
        season.text = seasonstr;
    }
    else
    {
        season.text = @"季节:";
    }
    season.top = texture.bottom+1;
    [detailscroll addSubview:season];
    */
    NumberInputView *input = [[NumberInputView alloc]initWithFrame:CGRectMake(self.view.height-320, 360, 315, 342)];
    input.top = background.top+5;
#ifdef DHH_iOS
    input.left = detail.right+2;
    
#else
    input.left = detail.right+2;
#endif

    input.backgroundColor = [UIColor colorWithRed:255/255.0 green:251/255.0 blue:236/255.0 alpha:1.0];
    input.delegate = self;
    [self.view addSubview:input];
    
    
    //如果有加大码则加载加大码视图
    if (bigobj) {
        bigView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 1024, 230)];
        bigView.userInteractionEnabled = YES;
        bigView.bounces = NO;
        [self.view addSubview:bigView];
        
        [self addBigObj:(NSString *)shopid shopname:(NSString *)shopname];
        
        view.height = 120;
        bigView.height = 120;
        
        bigView.top = view.bottom+5;
        
        
    }
    
    //如果有加裤则显示加裤标签，加裤没有加大码之分
    jkobj = [[DataManager sharedManager] getProductObjectByName:[product.pCode stringByAppendingString:@"JK"] andColor:product.pColorCode];
    
    if (jkobj) {
        UIButton *typejkbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        typejkbtn.frame = CGRectMake(0, 0, 80, 25);
        [typejkbtn setBackgroundImage:[UIImage imageNamed:@"anniu.png"] forState:UIControlStateNormal];
        [typejkbtn setTitle:@"加裤" forState:UIControlStateNormal];
        typejkbtn.origin = CGPointMake(sizeType.count*85+20, 0);
        [typejkbtn addTarget:self action:@selector(selectSizeType:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:typejkbtn];
        typejkbtn.top = tint.bottom+5;
        typejkbtn.tag = 1200;
        
        jkView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 1024, 230)];
        jkView.userInteractionEnabled = YES;
        jkView.bounces=NO;
        [self.view addSubview:jkView];
        
        [self addJKObj:(NSString *)shopid shopname:(NSString *)shopname];
        
        jkView.top = view.top;
        
        [jkView setHidden:YES];
    }

}

-(void)clearOrder:(UIButton *)sender{
    
    int num = sender.tag;
    
    if (num==20000) {
        for (int i = 0; i<sizegroupid.count; i++) {
            
            UITextField* txt = (UITextField*)[view viewWithTag:i+10];
            txt.text = @"0";
            
            SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
            [order setOrder:sizeobject.sSizeNo withQuantity:0 withShopID:numshopid];
        }
        UITextField* txt = (UITextField*)[view viewWithTag:110000];
        txt.text = @"0";
        
    }
    else if(num>=21000&&num<22000)
    {
        
        int tag = num -21000;
        for (int i = 0; i<sizegroupid.count; i++) {
            
            UITextField* txt = (UITextField*)[view viewWithTag:(tag+1)*100+i];
            txt.text = @"0";
            
            SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
            [[orders objectAtIndex:tag] setOrder:sizeobject.sSizeNo withQuantity:0 withShopID:numshopid];
        }
        UITextField* txt = (UITextField*)[view viewWithTag:110001+tag];
        txt.text = @"0";
        
    }
    
    else if(num ==22000)
    {
        for (int i = 0; i<sizegroupid.count; i++) {
            
            UITextField* txt = (UITextField*)[bigView viewWithTag:140000+i+10];
            txt.text = @"0";
            
            SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
            [bigorder setOrder:sizeobject.sSizeNo withQuantity:0 withShopID:numshopid];
        }
        UITextField* txt = (UITextField*)[bigView viewWithTag:120000];
        txt.text = @"0";
        
        
    }
    else if(num>=23000 && num <24000)
    {
        int tag = num -23000;
        for (int i = 0; i<sizegroupid.count; i++) {
            
            UITextField* txt = (UITextField*)[bigView viewWithTag:140000+i+100*(tag+1)];
            txt.text = @"0";
            
            SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
            [[bigorders objectAtIndex:tag] setOrder:sizeobject.sSizeNo withQuantity:0 withShopID:numshopid];
        }
        UITextField* txt = (UITextField*)[bigView viewWithTag:120001+tag];
        txt.text = @"0";
        
    }
    
    else if(num >=24000&& num<25000)
    {
        
        for (int i = 0; i<jksizegroupid.count; i++) {
            
            UITextField* txt = (UITextField*)[jkView viewWithTag:150000+i+10];
            txt.text = @"0";
            
            SizeObject *sizeobject = [jksizegroupid objectAtIndex:i];
            [jkorder setOrder:sizeobject.sSizeNo withQuantity:0 withShopID:numshopid];
        }
        UITextField* txt = (UITextField*)[jkView viewWithTag:130000];
        txt.text = @"0";
        
        
    }
    
    else{
        
        int tag = num -25000;
        for (int i = 0; i<jksizegroupid.count; i++) {
            
            UITextField* txt = (UITextField*)[jkView viewWithTag:150000+i+100*(tag+1)];
            txt.text = @"0";
            
            SizeObject *sizeobject = [jksizegroupid objectAtIndex:i];
            
            [[jkorders objectAtIndex:tag] setOrder:sizeobject.sSizeNo withQuantity:0 withShopID:numshopid];
        }
        UITextField* txt = (UITextField*)[jkView viewWithTag:130001+tag];
        txt.text = @"0";
        
        
    }
}


-(void)selectSizeType:(UIButton *)sender
{
    [self textFieldDidEndEditing:edittext];
    countnumber = 0;
    similarcountnumber = 0;
    sizetabindex = sender.tag-1100;
    text=nil;
    if (sizetabindex==100) {
        //加裤
        
        [bigView setHidden:YES];
        [view setHidden:YES];
        [jkView setHidden:NO];
        
        view.height = 230;
        
    }
    else{
        //其它版型
        sizegroupid = [[DataManager sharedManager] getSizeListBySizeGroup:obj.pSizeGroupID SizeType:[sizeType objectAtIndex:sizetabindex]];
        
        for (int i = 0; i<sizegroupid.count; i++) {
            
            SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
            UILabel *label = (UILabel*)[scroll viewWithTag:1500+i ];
            label.text = sizeobject.sSizeName;
            label = (UILabel*)[bigscroll viewWithTag:1500+i ];
            label.text = sizeobject.sSizeName;
            
            
            //切换的时候显示已经下过的订单数
            UITextField *textfield = (UITextField*) [scroll viewWithTag:10+i ];
            NSString *num = [NSString stringWithFormat:@"%d",[order getOrder:sizeobject.sSizeNo withShopID:numshopid]];
            textfield.text = num;
            
            textfield = (UITextField*) [bigscroll viewWithTag:140000+10+i ];
            num = [NSString stringWithFormat:@"%d",[bigorder getOrder:sizeobject.sSizeNo withShopID:numshopid]];
            textfield.text = num;
            
            
            
            for (int i = 0; i<similar.count; i++) {
                OrderObject *order1 = [orders objectAtIndex:i];
                
                for(int j=0;j<sizegroupid.count;j++)
                {
                    SizeObject *sizeobject = [sizegroupid objectAtIndex:j];
                    NSString * sizeno = sizeobject.sSizeNo ;
                    UITextField *textfield =(UITextField*) [scroll viewWithTag:j+100*(i+1) ];
                    NSString *num = [NSString stringWithFormat:@"%d",[order1 getOrder:sizeno withShopID:numshopid]];
                    textfield.text = num;
                    
                }
            }
            
            for (int i = 0; i<bigsimilar.count; i++) {
                OrderObject *order1 = [bigorders objectAtIndex:i];
        
                for(int j=0;j<sizegroupid.count;j++)
                {
                    SizeObject *sizeobject = [sizegroupid objectAtIndex:j];
                    NSString * sizeno = sizeobject.sSizeNo ;
                    UITextField *textfield =(UITextField*) [bigscroll viewWithTag:140000+j+100*(i+1) ];
                    NSString *num = [NSString stringWithFormat:@"%d",[order1 getOrder:sizeno withShopID:numshopid]];
                    textfield.text = num;

                }
            }
            
        }
        for (int i = 0; i<sizegroupid.count; i++) {
            UITextField *textfield = (UITextField*) [scroll viewWithTag:10+i ];
            countnumber+=[textfield.text intValue];
        }
        UILabel *label = (UILabel *)[view viewWithTag:110000];
        NSString *num = [NSString stringWithFormat:@"%d",countnumber];
        label.text = num;
        for (int i = 0; i<similar.count; i++) {
            similarcountnumber = 0;
            for(int j=0;j<sizegroupid.count;j++)
            {
                UITextField *textfield = (UITextField*) [scroll viewWithTag:j+100*(i+1) ];
                similarcountnumber+=[textfield.text intValue];
            }
            UILabel *label = (UILabel *)[view viewWithTag:110001+i];
            NSString *num = [NSString stringWithFormat:@"%d",similarcountnumber];
            label.text = num;
        }
        countnumber = 0;
        for (int i = 0; i<sizegroupid.count; i++) {
            UITextField *textfield = (UITextField*) [bigscroll viewWithTag:140000+10+i ];
            countnumber+=[textfield.text intValue];
        }
        UILabel *label1 = (UILabel *)[bigView viewWithTag:120000];
        NSString *num1 = [NSString stringWithFormat:@"%d",countnumber];
        label1.text = num1;
        for (int i = 0; i<similar.count; i++) {
            similarcountnumber = 0;
            for(int j=0;j<sizegroupid.count;j++)
            {
                UITextField *textfield = (UITextField*) [bigscroll viewWithTag:140000+j+100*(i+1) ];
                similarcountnumber+=[textfield.text intValue];
            }
            UILabel *label = (UILabel *)[bigView viewWithTag:120001+i];
            NSString *num = [NSString stringWithFormat:@"%d",similarcountnumber];
            label.text = num;
        }
        
        [bigView setHidden:NO];
        [view setHidden:NO];
        if (bigobj) {
            view.height = 120;
            bigView.height =120;
            bigView.top = view.bottom+5;
        }
        
        [jkView setHidden:YES];
        
    }
    
}

-(void)addBigObj:(NSString *)shopid shopname:(NSString *)shopname{
    //大码订单信息
    countnumber = 0;
    similarcountnumber = 0;
        bigsimilar = [[DataManager sharedManager] getSimiliarProduct:bigobj];
    
        bigscroll = [[UIScrollView alloc]initWithFrame:CGRectMake(172, 0, 630, bigView.height+200)];
        bigscroll.alwaysBounceVertical = NO;
        bigscroll.alwaysBounceHorizontal = YES;
        bigscroll.showsHorizontalScrollIndicator = NO;
        bigscroll.bounces = NO;
        [bigView addSubview:bigscroll];
        for (int i = 0; i<sizegroupid.count; i++) {
        
            SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
            if (sizegroupid.count<10) {
                width = bigscroll.width/sizegroupid.count;
            }
            else
            {
                width = 70;
            }
        
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(width*i+1, 0, width-1, 35)];
            label.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
            label.text = sizeobject.sSizeName;
            label.textColor = [UIColor whiteColor];
            label.tag = 1500+i;
            label.textAlignment = NSTextAlignmentCenter;
            [bigscroll addSubview:label];
            
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(width*(i+1), 0, 1, 70)];
            line.backgroundColor = [UIColor blackColor];
            [bigscroll addSubview:line];
            
            bigscroll.contentSize = CGSizeMake(width*(i+1), 70);
        }
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 70)];
        line1.backgroundColor = [UIColor blackColor];
        [bigView addSubview:line1];
    
        UIView *report = [[UIView alloc]initWithFrame:CGRectMake(20, 0, 152, 35)];
        report.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
        [bigView addSubview:report];
        
        UIView *reportline1 = [[UIView alloc]initWithFrame:CGRectMake(20, 0, 152, 35)];
        reportline1.backgroundColor = [UIColor whiteColor];
        reportline1.top = report.bottom;
        [bigView addSubview:reportline1];
        
        UIView *reportline2 = [[UIView alloc]initWithFrame:CGRectMake(20, 354, 980, 20)];
        reportline2.backgroundColor = [UIColor yellowColor];
        reportline2.top = reportline1.bottom;
        [bigView addSubview:reportline2];

        
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(95, 0, 1, 70)];
        line.backgroundColor = [UIColor blackColor];
        [bigView addSubview:line];
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(172, 0, 1, 70)];
        line2.backgroundColor = [UIColor blackColor];
        [bigView addSubview:line2];
    
    
    UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(803, 0, 199, 35)];
    report1.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
    [bigView addSubview:report1];
    
    UIView *reportline11 = [[UIView alloc]initWithFrame:CGRectMake(803, 0, 199, 35)];
    reportline11.backgroundColor = [UIColor whiteColor];
    reportline11.top = report1.bottom;
    [bigView addSubview:reportline11];

    UILabel *count = [[UILabel alloc]initWithFrame:CGRectMake(812, 0, 77, 35)];
    count.backgroundColor = [UIColor clearColor];
    count.text = @"小计";
    count.textColor = [UIColor whiteColor];
    count.textAlignment = NSTextAlignmentCenter;
    [bigView addSubview:count];
    
    UILabel *operate = [[UILabel alloc]initWithFrame:CGRectMake(892, 0, 77, 35)];
    operate.backgroundColor = [UIColor clearColor];
    operate.text = @"操作";
    operate.textColor = [UIColor whiteColor];
    operate.textAlignment = NSTextAlignmentCenter;
    [bigView addSubview:operate];
        
        UILabel *bigcode = [[UILabel alloc]initWithFrame:CGRectMake(20, 35, 75, 35)];
        bigcode.backgroundColor = [UIColor clearColor];
        NSString * str = [NSString stringWithFormat:@"%@(加大)",bigobj.pColorCode];
        bigcode.text = str;
        bigcode.textAlignment = NSTextAlignmentCenter;
        [bigView addSubview:bigcode];
        
        UILabel *bigcolor1 = [[UILabel alloc]initWithFrame:CGRectMake(95, 35, 75, 35)];
        bigcolor1.backgroundColor = [UIColor clearColor];
        bigcolor1.text = bigobj.pColor;
        bigcolor1.textAlignment = NSTextAlignmentCenter;
        [bigView addSubview:bigcolor1];
    
        UIView* dummyView = [[UIView alloc] initWithFrame:CGRectZero];
        
        reportline2.top = bigcode.bottom;
        
        UIView* bigdummyView = [[UIView alloc] initWithFrame:CGRectZero];
        for(int i=0;i<sizegroupid.count;i++)
        {
            SizeObject *sizeobject = [sizegroupid objectAtIndex:i];
            UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(1+ width*i, 35, width-1, 35)];
            textfield.backgroundColor = [UIColor whiteColor];
            textfield.delegate = self;
            NSString *num = [NSString stringWithFormat:@"%d",[bigorder getOrder:sizeobject.sSizeNo withShopID:numshopid]];
            textfield.text = num;
            textfield.tag = 140000+i+10;
            textfield.inputView = bigdummyView;
            textfield.textAlignment = NSTextAlignmentCenter;
            textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            [bigscroll addSubview:textfield];
            countnumber += [bigorder getOrder:sizeobject.sSizeNo withShopID:numshopid];
        }
        UILabel *countnum = [[UILabel alloc]initWithFrame:CGRectMake(812, 35, 77, 35)];
        countnum.backgroundColor = [UIColor clearColor];
        NSString *number = [NSString stringWithFormat:@"%d",countnumber];
        countnum.text = number;
        countnum.tag = 120000;
        countnum.textAlignment = NSTextAlignmentCenter;
        [bigView addSubview:countnum];
        if (numtag==0) {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
            [match setBackgroundImage:img3 forState:UIControlStateNormal];
            match.frame = CGRectMake(875, 40, 50, 25);
            match.tag = 20000;
            [match setTitle:@"搭配" forState:UIControlStateNormal];
            [match addTarget:self action:@selector(suit:) forControlEvents:UIControlEventTouchUpInside];
            [bigView addSubview:match];
            
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(930, 40, 50, 25);
            [proportion setTitle:@"清除" forState:UIControlStateNormal];
            proportion.tag =22000;
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            
            
            // [proportion setTitle:@"配比" forState:UIControlStateNormal];
            [bigView addSubview:proportion];
        }
        else
        {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(910, 40, 50, 25);
            [proportion setTitle:@"清除" forState:UIControlStateNormal];
            proportion.tag =22000;
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            [bigView addSubview:proportion];
        }
    
    
        //同款不同色
        for (int i = 0; i<bigsimilar.count; i++) {
            ProductObject *product = [bigsimilar objectAtIndex:i];
            OrderObject *orderobj = [[DataManager sharedManager]createOrderByProduct:product ShopId:shopid];
            [bigorders addObject:orderobj];
            OrderObject *order1 = [bigorders objectAtIndex:i];
            
            UIView *report = [[UIView alloc]initWithFrame:CGRectMake(20, 35*i+reportline2.bottom, 152, 35)];
            report.backgroundColor = [UIColor whiteColor];
            [bigView addSubview:report];
            
            UIView *line11 = [[UIView alloc]initWithFrame:CGRectMake(95, 0, 1, 35)];
            line11.backgroundColor = [UIColor blackColor];
            line11.top = report.top;
            [bigView addSubview:line11];
            
            UIView *line12 = [[UIView alloc]initWithFrame:CGRectMake(172, 0, 1, 35)];
            line12.backgroundColor = [UIColor blackColor];
            line12.top = report.top;
            [bigView addSubview:line12];
            
            UILabel *code = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 75, 35)];
            code.backgroundColor = [UIColor clearColor];
            NSString *str = [NSString stringWithFormat:@"%@(加大)",product.pColorCode];
            
            code.text = str;
            code.textAlignment = NSTextAlignmentCenter;
            code.top = report.top;
            [bigView addSubview:code];
            
            UILabel *color1 = [[UILabel alloc]initWithFrame:CGRectMake(95, 35, 75, 35)];
            color1.backgroundColor = [UIColor clearColor];
            color1.text = product.pColor;
            color1.top = report.top;
            color1.textAlignment = NSTextAlignmentCenter;
            [bigView addSubview:color1];
            
            for(int j=0;j<sizegroupid.count;j++)
            {
                SizeObject *sizeobject = [sizegroupid objectAtIndex:j];
                NSString * sizeno = sizeobject.sSizeNo ;
                UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(1 + width*j, 0, width-1, 35)];
                textfield.backgroundColor = [UIColor whiteColor];
                textfield.delegate = self;
                NSString *num = [NSString stringWithFormat:@"%d",[order1 getOrder:sizeno withShopID:numshopid]];
                textfield.text = num;
                textfield.tag = 140000+j+100*(i+1);
                textfield.top = report.top;
                textfield.inputView = dummyView;
                textfield.textAlignment = NSTextAlignmentCenter;
                textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
                [bigscroll addSubview:textfield];
                similarcountnumber += [order1 getOrder:sizeno withShopID:numshopid];
            }
            bigscroll.contentSize = CGSizeMake(bigscroll.contentSize.width, 95+(i*35));
            for (int j = 0; j<sizegroupid.count; j++) {
                UIView *line = [[UIView alloc]initWithFrame:CGRectMake(width*(j+1), 0, 1, 35)];
                line.backgroundColor = [UIColor blackColor];
                line.top = report.top;
                [bigscroll addSubview:line];
                
            }
            UIView *scrollline = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 35)];
            scrollline.backgroundColor = [UIColor blackColor];
            scrollline.top = report.top;
            [bigView addSubview:scrollline];
            
            UIView *scrollline1 = [[UIView alloc]initWithFrame:CGRectMake(0, line1.bottom, width*(sizegroupid.count), 1)];
            scrollline1.backgroundColor = [UIColor blackColor];
            scrollline1.top = report.bottom-1;
            [bigscroll addSubview:scrollline1];
            
            UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 35)];
            line1.backgroundColor = [UIColor blackColor];
            line1.top = report.top;
            [bigView addSubview:line1];
            
            UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(20, line1.bottom, 152, 1)];
            line2.backgroundColor = [UIColor blackColor];
            line2.top = report.bottom-1;
            [bigView addSubview:line2];
            
            UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(803, 90+i*35, 199, 35)];
            report1.backgroundColor = [UIColor whiteColor];
            [bigView addSubview:report1];
            
            UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(803, line1.bottom, 199, 1)];
            line3.backgroundColor = [UIColor blackColor];
            line3.top = report1.bottom-1;
            [bigView addSubview:line3];
            
            UILabel *countnumone = [[UILabel alloc]initWithFrame:CGRectMake(812, 90+i*35, 77, 35)];
            countnumone.backgroundColor = [UIColor clearColor];
            NSString *number = [NSString stringWithFormat:@"%d",similarcountnumber];
            countnumone.text = number;
            countnumone.tag = 120001+i;
            countnumone.textAlignment = NSTextAlignmentCenter;
            [bigView addSubview:countnumone];
            
            if (numtag==0) {
                UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
                UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
                [match setBackgroundImage:img3 forState:UIControlStateNormal];
                match.frame = CGRectMake(875, 90+35*i, 50, 25);
                match.tag = 100001+i;
                [match setTitle:@"搭配" forState:UIControlStateNormal];
                [match addTarget:self action:@selector(suit:) forControlEvents:UIControlEventTouchUpInside];
                [bigView addSubview:match];
                

                UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
                [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
                proportion.frame = CGRectMake(930, 95+35*i, 50, 25);
                [proportion setTitle:@"清除" forState:UIControlStateNormal];
                proportion.tag = 23000+i;
                [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
                
                [bigView addSubview:proportion];
            }
            else
            {
                
                UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
                UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
                [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
                proportion.frame = CGRectMake(910, 95+35*i, 50, 25);
                [proportion setTitle:@"清除" forState:UIControlStateNormal];
                proportion.tag = 23000+i;
                [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
                
                [bigView addSubview:proportion];
            }
            
            bigView.contentSize = CGSizeMake(bigView.width, bigscroll.contentSize.height+80);
            
        }
    
}

-(void)addJKObj:(NSString *)shopid shopname:(NSString *)shopname{
    //加裤订单信息
    countnumber = 0;
    similarcountnumber = 0;
    jksizegroupid = [[DataManager sharedManager] getSizeListBySizeGroup:jkobj.pSizeGroupID SizeType:@""];
    jksimilar = [[DataManager sharedManager] getSimiliarProduct:jkobj];
    
    jkscroll = [[UIScrollView alloc]initWithFrame:CGRectMake(172, 0, 630, jkscroll.height+200)];
    jkscroll.alwaysBounceVertical = NO;
    jkscroll.alwaysBounceHorizontal = YES;
    jkscroll.showsHorizontalScrollIndicator = NO;
    jkscroll.bounces = NO;
    [jkView addSubview:jkscroll];
    for (int i = 0; i<jksizegroupid.count; i++) {
        
        SizeObject *sizeobject = [jksizegroupid objectAtIndex:i];
        if (jksizegroupid.count<10) {
            width = jkscroll.width/jksizegroupid.count;
        }
        else
        {
            width = 70;
        }
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(width*i+1, 0, width-1, 35)];
        label.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
        label.text = sizeobject.sSizeName;
        label.tag = 1500+i;
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        [jkscroll addSubview:label];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(width*(i+1), 0, 1, 70)];
        line.backgroundColor = [UIColor blackColor];
        [jkscroll addSubview:line];
        
        jkscroll.contentSize = CGSizeMake(width*(i+1), 70);
    }
    UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 70)];
    line1.backgroundColor = [UIColor blackColor];
    [jkView addSubview:line1];
    
    UIView *report = [[UIView alloc]initWithFrame:CGRectMake(20, 0, 152, 35)];
    report.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
    [jkView addSubview:report];
    
    UIView *reportline1 = [[UIView alloc]initWithFrame:CGRectMake(20, 0, 152, 35)];
    reportline1.backgroundColor = [UIColor whiteColor];
    reportline1.top = report.bottom;
    [jkView addSubview:reportline1];
    
    UIView *reportline2 = [[UIView alloc]initWithFrame:CGRectMake(20, 354, 980, 20)];
    reportline2.backgroundColor = [UIColor yellowColor];
    reportline2.top = reportline1.bottom;
    [jkView addSubview:reportline2];
    
    
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(95, 0, 1, 70)];
    line.backgroundColor = [UIColor blackColor];
    [jkView addSubview:line];
    
    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(172, 0, 1, 70)];
    line2.backgroundColor = [UIColor blackColor];
    [jkView addSubview:line2];
    
    
    UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(803, 0, 199, 35)];
    report1.backgroundColor = [UIColor colorWithRed:180/255.0 green:145/255.0 blue:106/255.0 alpha:1];
    [jkView addSubview:report1];
    
    UIView *reportline11 = [[UIView alloc]initWithFrame:CGRectMake(803, 0, 199, 35)];
    reportline11.backgroundColor = [UIColor whiteColor];
    reportline11.top = report1.bottom;
    [jkView addSubview:reportline11];
    
    UILabel *count = [[UILabel alloc]initWithFrame:CGRectMake(812, 0, 77, 35)];
    count.backgroundColor = [UIColor clearColor];
    count.text = @"小计";
    count.textColor = [UIColor whiteColor];
    count.textAlignment = NSTextAlignmentCenter;
    [jkView addSubview:count];
    
    UILabel *operate = [[UILabel alloc]initWithFrame:CGRectMake(892, 0, 77, 35)];
    operate.backgroundColor = [UIColor clearColor];
    operate.text = @"操作";
    operate.textColor = [UIColor whiteColor];
    operate.textAlignment = NSTextAlignmentCenter;
    [jkView addSubview:operate];
    
    UILabel *bigcode = [[UILabel alloc]initWithFrame:CGRectMake(20, 35, 75, 35)];
    bigcode.backgroundColor = [UIColor clearColor];
    NSString * str = jkobj.pColorCode;
    bigcode.text = str;
    bigcode.textAlignment = NSTextAlignmentCenter;
    [jkView addSubview:bigcode];
    
    UILabel *bigcolor1 = [[UILabel alloc]initWithFrame:CGRectMake(95, 35, 75, 35)];
    bigcolor1.backgroundColor = [UIColor clearColor];
    bigcolor1.text = jkobj.pColor;
    bigcolor1.textAlignment = NSTextAlignmentCenter;
    [jkView addSubview:bigcolor1];
    
    UIView* dummyView = [[UIView alloc] initWithFrame:CGRectZero];
    
    reportline2.top = bigcode.bottom;
    
    UIView* bigdummyView = [[UIView alloc] initWithFrame:CGRectZero];
    for(int i=0;i<jksizegroupid.count;i++)
    {
        SizeObject *sizeobject = [jksizegroupid objectAtIndex:i];
        UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(1+ width*i, 35, width-1, 35)];
        textfield.backgroundColor = [UIColor whiteColor];
        textfield.delegate = self;
        NSString *num = [NSString stringWithFormat:@"%d",[jkorder getOrder:sizeobject.sSizeNo withShopID:numshopid]];
        textfield.text = num;
        textfield.tag = 150000+i+10;
        textfield.inputView = bigdummyView;
        textfield.textAlignment = NSTextAlignmentCenter;
        textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [jkscroll addSubview:textfield];
        countnumber += [jkorder getOrder:sizeobject.sSizeNo withShopID:numshopid];
    }
    UILabel *countnum = [[UILabel alloc]initWithFrame:CGRectMake(812, 35, 77, 35)];
    countnum.backgroundColor = [UIColor clearColor];
    NSString *number = [NSString stringWithFormat:@"%d",countnumber];
    countnum.text = number;
    countnum.tag = 130000;
    countnum.textAlignment = NSTextAlignmentCenter;
    [jkView addSubview:countnum];
    
    if (numtag==0) {
        UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
        UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
        [match setBackgroundImage:img3 forState:UIControlStateNormal];
        match.frame = CGRectMake(875, 40, 50, 25);
        match.tag = 20000;
        [match setTitle:@"搭配" forState:UIControlStateNormal];
        [match addTarget:self action:@selector(suit:) forControlEvents:UIControlEventTouchUpInside];
        [jkView addSubview:match];
        
        UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
        [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
        proportion.frame = CGRectMake(930, 40, 50, 25);
        [proportion setTitle:@"清除" forState:UIControlStateNormal];
        proportion.tag = 24000;
        [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
        
        [jkView addSubview:proportion];
    }
    else
    {
        
        UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
        UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
        [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
        proportion.frame = CGRectMake(910, 40, 50, 25);
        [proportion setTitle:@"清除" forState:UIControlStateNormal];
        proportion.tag = 24000;
        [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
        
        [jkView addSubview:proportion];
    }
    
    //同款不同色
    for (int i = 0; i<jksimilar.count; i++) {
        ProductObject *product = [jksimilar objectAtIndex:i];
        OrderObject *orderobj = [[DataManager sharedManager]createOrderByProduct:product ShopId:shopid];
        [jkorders addObject:orderobj];
        OrderObject *order1 = [jkorders objectAtIndex:i];
        
        UIView *report = [[UIView alloc]initWithFrame:CGRectMake(20, 35*i+reportline2.bottom, 152, 35)];
        report.backgroundColor = [UIColor whiteColor];
        [jkView addSubview:report];
        
        UIView *line11 = [[UIView alloc]initWithFrame:CGRectMake(95, 0, 1, 35)];
        line11.backgroundColor = [UIColor blackColor];
        line11.top = report.top;
        [jkView addSubview:line11];
        
        UIView *line12 = [[UIView alloc]initWithFrame:CGRectMake(172, 0, 1, 35)];
        line12.backgroundColor = [UIColor blackColor];
        line12.top = report.top;
        [jkView addSubview:line12];
        
        UILabel *code = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 75, 35)];
        code.backgroundColor = [UIColor clearColor];
        NSString *str = product.pColorCode;
        
        code.text = str;
        code.textAlignment = NSTextAlignmentCenter;
        code.top = report.top;
        [jkView addSubview:code];
        
        UILabel *color1 = [[UILabel alloc]initWithFrame:CGRectMake(95, 35, 75, 35)];
        color1.backgroundColor = [UIColor clearColor];
        color1.text = product.pColor;
        color1.top = report.top;
        color1.textAlignment = NSTextAlignmentCenter;
        [jkView addSubview:color1];
        
        for(int j=0;j<jksizegroupid.count;j++)
        {
            SizeObject *sizeobject = [jksizegroupid objectAtIndex:j];
            NSString * sizeno = sizeobject.sSizeNo ;
            UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(1 + width*j, 0, width-1, 35)];
            textfield.backgroundColor = [UIColor whiteColor];
            textfield.delegate = self;
            NSString *num = [NSString stringWithFormat:@"%d",[order1 getOrder:sizeno withShopID:numshopid]];
            textfield.text = num;
            textfield.tag = 150000+j+100*(i+1);
            textfield.top = report.top;
            textfield.inputView = dummyView;
            textfield.textAlignment = NSTextAlignmentCenter;
            textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            [jkscroll addSubview:textfield];
            similarcountnumber += [order1 getOrder:sizeno withShopID:numshopid];
        }
        jkscroll.contentSize = CGSizeMake(jkscroll.contentSize.width, 95+(i*35));
        for (int j = 0; j<jksizegroupid.count; j++) {
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(width*(j+1), 0, 1, 35)];
            line.backgroundColor = [UIColor blackColor];
            line.top = report.top;
            [jkscroll addSubview:line];
            
        }
        UIView *scrollline = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 35)];
        scrollline.backgroundColor = [UIColor blackColor];
        scrollline.top = report.top;
        [jkView addSubview:scrollline];
        
        UIView *scrollline1 = [[UIView alloc]initWithFrame:CGRectMake(0, line1.bottom, width*(jksizegroupid.count), 1)];
        scrollline1.backgroundColor = [UIColor blackColor];
        scrollline1.top = report.bottom-1;
        [jkscroll addSubview:scrollline1];
        
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(802, 0, 1, 35)];
        line1.backgroundColor = [UIColor blackColor];
        line1.top = report.top;
        [jkView addSubview:line1];
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(20, line1.bottom, 152, 1)];
        line2.backgroundColor = [UIColor blackColor];
        line2.top = report.bottom-1;
        [jkView addSubview:line2];
        
        UIView *report1 = [[UIView alloc]initWithFrame:CGRectMake(803, 90+i*35, 199, 35)];
        report1.backgroundColor = [UIColor whiteColor];
        [jkView addSubview:report1];
        
        UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(803, line1.bottom, 199, 1)];
        line3.backgroundColor = [UIColor blackColor];
        line3.top = report1.bottom-1;
        [jkView addSubview:line3];
        
        UILabel *countnumone = [[UILabel alloc]initWithFrame:CGRectMake(812, 90+i*35, 77, 35)];
        countnumone.backgroundColor = [UIColor clearColor];
        NSString *number = [NSString stringWithFormat:@"%d",similarcountnumber];
        countnumone.text = number;
        countnumone.tag = 130001+i;
        countnumone.textAlignment = NSTextAlignmentCenter;
        [jkView addSubview:countnumone];
        
        if (numtag==0) {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *match = [UIButton buttonWithType:UIButtonTypeCustom];
            [match setBackgroundImage:img3 forState:UIControlStateNormal];
            match.frame = CGRectMake(875, 90+35*i, 50, 25);
            match.tag = 100001+i;
            [match setTitle:@"搭配" forState:UIControlStateNormal];
            [match addTarget:self action:@selector(suit:) forControlEvents:UIControlEventTouchUpInside];
            [jkView addSubview:match];
            
            
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(930, 95+35*i, 50, 25);
            proportion.tag = 25000+i;
            [proportion setTitle:@"清除" forState:UIControlStateNormal];
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            
            
            [jkView addSubview:proportion];
        }
        else
        {
            UIImage *img3 = [UIImage imageNamed:@"anniu.png"];
            UIButton *proportion = [UIButton buttonWithType:UIButtonTypeCustom];
            [proportion setBackgroundImage:img3 forState:UIControlStateNormal];
            proportion.frame = CGRectMake(910, 95+35*i, 50, 25);
            [proportion setTitle:@"清除" forState:UIControlStateNormal];
            proportion.tag = 25000+i;
            [proportion addTarget:self action:@selector(clearOrder:) forControlEvents:UIControlEventTouchUpInside];
            [jkView addSubview:proportion];
        }
        jkView.contentSize = CGSizeMake(jkView.width, jkscroll.contentSize.height+80);
        
    }
    
}



- (void)tap{
    NSString * path = [[[PMGlobal getInstance] getImageURL] stringByAppendingPathComponent:obj.pURL];
    NSArray *array = [NSArray arrayWithObject:path];
    PictureViewController *pic = [[PictureViewController alloc] initWithPictures:array withFrame:self.view.frame Desc:nil];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pic];
    [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBar.png"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController presentModalViewController:nav animated:YES];

}

-(void)ret
{
#ifdef DHH_iOS
    [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshnum" object:nil];
#endif
    if (numobjtag == 1) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar1.png"] forBarMetrics:UIBarMetricsDefault];
    }
    if (numobjtag != 2) {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"hidden" object:nil];
    }
    
    //  [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshorder" object:nil];
    [self.navigationController popViewControllerAnimated:YES];

}

-(void)save
{
    [self textFieldDidEndEditing:edittext];
    [[DataManager sharedManager]placeOrder:order];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"numreload" object:obj];
    //有加大的保存加裤信息
    if(bigobj){
        [[DataManager sharedManager]placeOrder:bigorder];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"numreload" object:bigobj];
        
        for (int i = 0; i<bigsimilar.count; i++) {
            OrderObject *orderobj = [bigorders objectAtIndex:i];
            [[DataManager sharedManager]placeOrder:orderobj];
            ProductObject *product = [bigsimilar objectAtIndex:i];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"numreload" object:product];
        }
        
    }
    //有加裤的保存加裤信息
    if(jkobj){
        [[DataManager sharedManager]placeOrder:jkorder];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"numreload" object:jkobj];
        
        for (int i = 0; i<jksimilar.count; i++) {
            OrderObject *orderobj = [jkorders objectAtIndex:i];
            [[DataManager sharedManager]placeOrder:orderobj];
            ProductObject *product = [jksimilar objectAtIndex:i];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"numreload" object:product];
        }
        
    }
    
    
    for (int i = 0; i<similar.count; i++) {
        OrderObject *orderobj = [orders objectAtIndex:i];
        [[DataManager sharedManager]placeOrder:orderobj];
        ProductObject *product = [similar objectAtIndex:i];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"numreload" object:product];
    }
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"保存成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}

-(void)collect:(UIButton *)sender
{
    if ([[DataManager sharedManager]productIsFavorite:obj Shopid:nil]==0) {
        [[DataManager sharedManager]setAsFavorite:obj withStar:sender.tag-10000+1 Shopid:@" "];
       // [collect setBackgroundImage:[UIImage imageNamed:@"collect_redimage.png"] forState:UIControlStateNormal];
        for (int i = 0; i<5; i++) {
            UIButton *btn = (UIButton *)[self.view viewWithTag:10000+i];
            if(i<[[DataManager sharedManager]productIsFavorite:obj Shopid:nil])
            {
                [btn setBackgroundImage:[UIImage imageNamed:@"collect_redimage.png"] forState:UIControlStateNormal];
            }
        }
        [[NSNotificationCenter defaultCenter]postNotificationName:@"collectreload" object:obj];
    }
    else
    {
        //  [collect setBackgroundImage:[UIImage imageNamed:@"collect_image.png"] forState:UIControlStateNormal];
        if (sender.tag - 10000+1 == [[DataManager sharedManager]productIsFavorite:obj Shopid:nil]) {
            for (int i = 0; i<5; i++) {
                UIButton *btn = (UIButton *)[self.view viewWithTag:10000+i];
                [btn setBackgroundImage:[UIImage imageNamed:@"collect_image.png"] forState:UIControlStateNormal];
            }
            [[DataManager sharedManager]cancelAsFavorite:obj Shopid:nil];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"uncollectreload" object:obj];
        }
        else
        {
            [[DataManager sharedManager]cancelAsFavorite:obj Shopid:nil];
            [[DataManager sharedManager]setAsFavorite:obj withStar:sender.tag-10000+1 Shopid:@" "];
            for (int i = 0; i<5; i++) {
            UIButton *btn = (UIButton *)[self.view viewWithTag:10000+i];
            if(i<[[DataManager sharedManager]productIsFavorite:obj Shopid:nil])
            {
                [btn setBackgroundImage:[UIImage imageNamed:@"collect_redimage.png"] forState:UIControlStateNormal];
            }
            else
            {
                [btn setBackgroundImage:[UIImage imageNamed:@"collect_image.png"] forState:UIControlStateNormal];
            }
        }
        }
    }
}

-(void)numberInputViewDidClick:(NSString *)clickValue
{
    text.text = clickValue;
    
    if (text.tag!=1000) {
        if (text) {
            totalnum = totalnum1 + [text.text intValue] - textnum;
            NSString *str = [NSString stringWithFormat:@"订单总量：%d",totalnum];
            totallabel.text = str;

        }
        searchtext = nil;
    countnumber = 0;
    similarcountnumber = 0;
    if (text.tag<100) {
    for(int i = 0;i<sizegroupid.count;i++)
    {
    UITextField *textfield = (UITextField *)[self.scroll viewWithTag:i+10];
    NSLog(@"%@",textfield.text);
        countnumber += [textfield.text intValue];
    }
    UILabel *countnum = (UILabel *)[view viewWithTag:110000];
    NSString *num = [NSString stringWithFormat:@"%d",countnumber];
    countnum.text = num;
    countnum.textAlignment = NSTextAlignmentCenter;
    }
    else if(text.tag>=100&&text.tag<1000)
    {
        for(int i = 0;i<sizegroupid.count;i++)
        {
            UITextField *textfield = (UITextField *)[self.scroll viewWithTag:text.tag/100*100+i];
            NSLog(@"%@",textfield.text);
            similarcountnumber += [textfield.text intValue];
        }
        UILabel *countnumone = (UILabel *)[view viewWithTag:110000+text.tag/100];
        NSString *num = [NSString stringWithFormat:@"%d",similarcountnumber];
        countnumone.text = num;
        countnumone.textAlignment = NSTextAlignmentCenter;
    }
        else if(text.tag>=140000&&text.tag<140100)
        {
            for(int i = 0;i<sizegroupid.count;i++)
            {
                UITextField *textfield = (UITextField *)[bigscroll viewWithTag:140000+i+10];
                NSLog(@"%@",textfield.text);
                countnumber += [textfield.text intValue];
            }
            UILabel *countnum = (UILabel *)[bigView viewWithTag:120000];
            NSString *num = [NSString stringWithFormat:@"%d",countnumber];
            countnum.text = num;
            countnum.textAlignment = NSTextAlignmentCenter;
        }
        else if(text.tag>=140100&&text.tag<141000)
        {
            for(int i = 0;i<sizegroupid.count;i++)
            {
                UITextField *textfield = (UITextField *)[bigView viewWithTag:text.tag/100*100+i];
                NSLog(@"%@",textfield.text);
                similarcountnumber += [textfield.text intValue];
            }
            UILabel *countnumone = (UILabel *)[bigView viewWithTag:120000+(text.tag-140000)/100];
            NSString *num = [NSString stringWithFormat:@"%d",similarcountnumber];
            countnumone.text = num;
            countnumone.textAlignment = NSTextAlignmentCenter;
        }
        else if(text.tag>=150000&&text.tag<150100)
        {
            for(int i = 0;i<jksizegroupid.count;i++)
            {
                UITextField *textfield = (UITextField *)[jkscroll viewWithTag:150000+i+10];
                NSLog(@"%@",textfield.text);
                countnumber += [textfield.text intValue];
            }
            UILabel *countnum = (UILabel *)[jkView viewWithTag:130000];
            NSString *num = [NSString stringWithFormat:@"%d",countnumber];
            countnum.text = num;
            countnum.textAlignment = NSTextAlignmentCenter;
        }
        else if(text.tag>=150100&&text.tag<151000)
        {
            for(int i = 0;i<jksizegroupid.count;i++)
            {
                UITextField *textfield = (UITextField *)[jkscroll viewWithTag:text.tag/100*100+i];
                NSLog(@"%@",textfield.text);
                similarcountnumber += [textfield.text intValue];
            }
            UILabel *countnumone = (UILabel *)[jkView viewWithTag:130000+(text.tag-150000)/100];
            NSString *num = [NSString stringWithFormat:@"%d",similarcountnumber];
            countnumone.text = num;
            countnumone.textAlignment = NSTextAlignmentCenter;
        }
    }
    else
    {
        searchtext = text.text;
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    textnum = [textField.text intValue];
    totalnum1 = totalnum;
    edittext = textField;
    if (textField.tag==1000) {
    }
    else
    {
        [textField setBackground:[UIImage imageNamed:@"order_click.png"]];
        ProductObject *product = [[ProductObject alloc]init];
        if (textField.tag%10000/100-1<0) {
            product = obj;
        }
        else
        {
        product = [similar objectAtIndex:textField.tag%10000/100-1];
        }
        NSString *url = [NSString stringWithFormat:@"%@",product.pThumbURL];
        NSString * path = [[[PMGlobal getInstance] getImageURL] stringByAppendingPathComponent:url];
        productImage_.image = [imageCache_ imageForKey:product.pThumbURL url:[NSURL URLWithString:path] queueIfNeeded:YES tag:0];
    }
    if ([textField.text isEqualToString:@"0"])
    {
        textField.text = @"";
    }
    text = textField;
    NSString *str = text.text;
    [[NSNotificationCenter defaultCenter]postNotificationName:@"clear" object:str];
    
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    return YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField) {
        
    
        if (textField.tag != 1000) {
            int num = textField.tag;
            
            if ([textField.text isEqualToString:@""]) {
                textField.text = @"0";
            }
            
            int orderNumber = [textField.text intValue];
            
            if (num<100) {
                SizeObject *sizeobject = [sizegroupid objectAtIndex:num-10];
                [order setOrder:sizeobject.sSizeNo withQuantity:orderNumber withShopID:numshopid];
            }
            else if(num >=140000&& num<140100)
            {
                SizeObject *sizeobject = [sizegroupid objectAtIndex:num-140000-10];
                [bigorder setOrder:sizeobject.sSizeNo withQuantity:orderNumber withShopID:numshopid];
            }
            else if(num >=150000&& num<150100)
            {
                SizeObject *sizeobject = [sizegroupid objectAtIndex:num-150000-10];
                [jkorder setOrder:sizeobject.sSizeNo withQuantity:orderNumber withShopID:numshopid];
            }
            else if(num>=100&&num<1000)
            {
                SizeObject *sizeobject = [sizegroupid objectAtIndex:num%100];
                [[orders objectAtIndex:num/100-1] setOrder:sizeobject.sSizeNo withQuantity:orderNumber withShopID:numshopid];
            }
            else if(num>=140100 && num <141000)
            {
                SizeObject *sizeobject = [sizegroupid objectAtIndex:num%140000%100];
                [[bigorders objectAtIndex:(num-140000)/100-1] setOrder:sizeobject.sSizeNo withQuantity:orderNumber withShopID:numshopid];
            }
            else{
                SizeObject *sizeobject = [jksizegroupid objectAtIndex:num%150000%100];
                
                [[jkorders objectAtIndex:(num-150000)/100-1] setOrder:sizeobject.sSizeNo withQuantity:orderNumber withShopID:numshopid];
            }
            
            textField.background = [UIImage imageNamed:@"clear.png"];
            [textField resignFirstResponder];
        }
        else
        {
            // obj = [[DataManager sharedManager]searchProductWithSimCode:textField.text];
            // [self refresh:obj];
        }
    }

}


-(void)search:(NSNotification *)sender
{
    [items removeAllObjects];
    items = [NSMutableArray array];
    if (searchtext&&isclick == NO) {
        obj = [[DataManager sharedManager]searchProductWithSimCode:searchtext];
        if (obj) {
#ifdef DHH_iOS
            [self iphoneUI:[user.shopID objectAtIndex:0]
                  shopname:user.userName];
#else
            [self ipadUI:obj shopid:numshopid shopname:user.userName tag:0];
#endif
        }
    }
    else if(searchtext&&isclick == YES)
    {
        searchproduct = [[DataManager sharedManager] searchProductWithCode:searchtext];
        for (int i = 0; i<searchproduct.count; i++) {
            ProductObject *obj1 = [searchproduct objectAtIndex:i];
            [items addObject:obj1.pCode];
        }
        
        
        controller = [[ShopViewController alloc] initWithStyle:UITableViewStylePlain items:items tag:11];
        
        FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
        
        //popover.arrowDirection = FPPopoverArrowDirectionAny;
        popover.tint = FPPopoverDefaultTint;
        
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            popover.contentSize = CGSizeMake(300, 500);
        }
        popover.arrowDirection = FPPopoverArrowDirectionUp;
        
        //sender is the UIButton view
        [popover presentPopoverFromView:codesearch];

    }
    UITextField *text1 = [[UITextField alloc]init];
    if (edittext.tag<1000) {
        text1 = (UITextField *)[self.scroll viewWithTag:edittext.tag+1];
    }
    else if(edittext.tag>=140000&&edittext.tag<150000)
    {
        text1 = (UITextField *)[bigscroll viewWithTag:edittext.tag+1];
    }
    else
    {
        text1 = (UITextField *)[jkscroll viewWithTag:edittext.tag+1];
    }
    if (text1) {
        [self textFieldDidEndEditing:edittext];
        [text1 becomeFirstResponder];
        [self textFieldDidBeginEditing:text1];
    }

}


-(void)copy1
{
    if(shop.count<2)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"其他店铺不存在"
                                                      delegate:nil cancelButtonTitle:@"确定"
                                             otherButtonTitles:nil];
        [alert show];
    }
    else
    {
        copytopaste = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail_copyback.png"]];
        copytopaste.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_copyback.png"].size.width, [UIImage imageNamed:@"detail_copyback.png"].size.height);
        copytopaste.center = CGPointMake(512, 300);
        copytopaste.userInteractionEnabled = YES;
        [self.view addSubview:copytopaste];
        
        UIButton *paste = [UIButton buttonWithType:UIButtonTypeCustom];
        [paste setImage:[UIImage imageNamed:@"detail_paste"] forState:UIControlStateNormal];
        paste.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_paste"].size.width, [UIImage imageNamed:@"detail_paste"].size.height);
        paste.center = CGPointMake([UIImage imageNamed:@"detail_copyback.png"].size.width/2-100, 320);
        [paste addTarget:self action:@selector(pasteclick) forControlEvents:UIControlEventTouchUpInside];
        [copytopaste addSubview:paste];
        
        UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancel setImage:[UIImage imageNamed:@"detail_cancel"] forState:UIControlStateNormal];
        cancel.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_cancel"].size.width, [UIImage imageNamed:@"detail_cancel"].size.height);
        cancel.center = CGPointMake([UIImage imageNamed:@"detail_copyback.png"].size.width/2+100, 320);
        [cancel addTarget:self action:@selector(cancelclick) forControlEvents:UIControlEventTouchUpInside];
        [copytopaste addSubview:cancel];
        
        shoparray = [[NSMutableArray alloc]init];
        for (int i = 0; i<shop.count; i++) {
            ShopObject *copyshop = [shop objectAtIndex:i];
            if(![user.userName isEqualToString:copyshop.shopName])
            {
                [shoparray addObject:copyshop];
            }
        }
    
        for (int i = 0; i<shoparray.count; i++) {
            ShopObject *copyshop = [shoparray objectAtIndex:i];
            
            shopview = [[UIView alloc]initWithFrame:CGRectMake(10, 70 + i *50, 345, 50)];
            shopview.layer.borderWidth = 1;
            shopview.layer.borderColor = [UIColor grayColor].CGColor;
            [copytopaste addSubview:shopview];
            
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(290, 1, 1, 50)];
            line.backgroundColor = [UIColor grayColor];
            [shopview addSubview:line];
            
            UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
            label.center = CGPointMake(150, 25);
            label.textAlignment = NSTextAlignmentCenter;
            label.text = copyshop.shopName;
            [shopview addSubview:label];
            
            UIButton *select = [UIButton buttonWithType:UIButtonTypeCustom];
            [select setImage:[UIImage imageNamed:@"detail_shopunselect.png"] forState:UIControlStateNormal];
            select.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_shopunselect.png"].size.width, [UIImage imageNamed:@"detail_shopunselect.png"].size.height);
            select.center = CGPointMake(318, 25);
            select.tag = 10 + i;
            [select addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            [shopview addSubview:select];
        }
    }
}

-(void)keyClicked:(UIButton *)sender
{
    
  //  UIButton *btn = (UIButton *)[view viewWithTag:sender.tag];
  //  [btn setBackgroundColor:[UIColor colorWithRed:192/255.0 green:192/255.0 blue:192/255.0 alpha:1]];
  //  [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  //  [btn setImage:nil forState:UIControlStateNormal];

   // [popup removeFromSuperview];
    [items removeAllObjects];
    items = [NSMutableArray array];
    for (int i = 0;i<shop.count;i++) {
        ShopObject *shopobj = [shop objectAtIndex:i];
        [items addObject:shopobj.shopName];
    }
    /*
    popup = [[PopupView alloc] initWithFrame:sender.frame withItems:items withHighlight:0 width:sender.left+35 tag:sender.tag];
    popup.delegate = self;
    [self.view addSubview:popup];
     */
    //the controller we want to present as a popover
    controller = [[ShopViewController alloc] initWithStyle:UITableViewStylePlain items:items tag:sender.tag];
    
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
    
    //popover.arrowDirection = FPPopoverArrowDirectionAny;
    popover.tint = FPPopoverDefaultTint;
    
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        popover.contentSize = CGSizeMake(300, 500);
    }
    popover.arrowDirection = FPPopoverArrowDirectionUp;
    
    //sender is the UIButton view
    [popover presentPopoverFromView:sender];
}



-(void)getshop
{
    
}

-(void)pasteclick
{
    [shopidarray removeAllObjects];
    [orders removeAllObjects];
    for (int i = 0; i<shoparray.count; i++) {
        UIButton *btn = (UIButton *)[copytopaste viewWithTag:10+i];
        if (btn.imageView.image == [UIImage imageNamed:@"detail_shopunselect.png"]) {
            [shopidarray addObject:@"0"];
        }
        else {
            [shopidarray addObject:@"1"];
        }
    }
    for (int i = 0; i<shopidarray.count; i++) {
        if ([[shopidarray objectAtIndex:i] isEqualToString:@"1"]) {
            ShopObject *shopobj = [shoparray objectAtIndex:i];
            for(int j=0;j<sizegroupid.count;j++)
            {
                SizeObject *sizeobject = [sizegroupid objectAtIndex:j];
                int num = [order getOrder:sizeobject.sSizeNo withShopID:numshopid];
                [order setOrder:sizeobject.sSizeNo withQuantity:num withShopID:shopobj.shopID];
                
                countnumber += [order getOrder:sizeobject.sSizeNo withShopID:numshopid];
            }
            for (int j = 0; j<similar.count; j++) {
                ProductObject *product = [similar objectAtIndex:j];
                OrderObject *orderobj = [[DataManager sharedManager]createOrderByProduct:product ShopId:shopobj.shopID];
                [orders addObject:orderobj];
                OrderObject *order1 = [orders objectAtIndex:j];
                for(int k=0;k<sizegroupid.count;k++)
                {
                    SizeObject *sizeobject = [sizegroupid objectAtIndex:k];
                    int num = [order1 getOrder:sizeobject.sSizeNo withShopID:numshopid];
                    [order1 setOrder:sizeobject.sSizeNo withQuantity:num withShopID:shopobj.shopID];
                    
                    countnumber += [order getOrder:sizeobject.sSizeNo withShopID:numshopid];
                }
            }
        }
    }
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"复制完毕" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}
/*
-(void)dismiss:(NSNotification *)sender
{
    NSString *tag = sender.object;
    UIButton *btn = (UIButton *)[view viewWithTag:[tag intValue]];
    [btn setBackgroundColor:[UIColor clearColor]];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"order_next.png"] forState:UIControlStateNormal];
    isclear = YES;
}
*/
-(void)cancelclick
{
    [copytopaste removeFromSuperview];
}

-(void)click:(UIButton *)sender
{
    UIButton *btn = (UIButton *)[copytopaste viewWithTag:sender.tag];
    if(btn.imageView.image == [UIImage imageNamed:@"detail_shopunselect.png"])
    {
        [btn setImage:[UIImage imageNamed:@"detail_shopselect.png"] forState:UIControlStateNormal];
        btn.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_shopselect.png"].size.width, [UIImage imageNamed:@"detail_shopselect.png"].size.height);
        btn.center = CGPointMake(322, 22);

    }
    else
    {
        [btn setImage:[UIImage imageNamed:@"detail_shopunselect.png"] forState:UIControlStateNormal];
        btn.frame = CGRectMake(0, 0, [UIImage imageNamed:@"detail_shopunselect.png"].size.width, [UIImage imageNamed:@"detail_shopunselect.png"].size.height);
        btn.center = CGPointMake(318, 25);
    }
    
}

#pragma mark
- (void)popupViewClicked:(PopupView *)popup atIndex:(int)clickedIndex{
    ShopObject *shopobj = [shop objectAtIndex:clickedIndex];
    [self ipadUI:obj shopid:shopobj.shopID shopname:shopobj.shopName tag:0];
}

-(void)index1:(NSNotification *)sender
{
    NSString *str = sender.object;
    int index = [str intValue];
    ShopObject *shopobj = [shop objectAtIndex:index];
    [self ipadUI:obj shopid:shopobj.shopID shopname:shopobj.shopName tag:0];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"dismissPopover" object:nil];
}

-(void)selectcode
{
    [codesearch removeFromSuperview];
    if(isclick == NO)
    {
        codesearch = [[UITextField alloc]initWithFrame:CGRectMake(780, 12, 100, 20)];
        codesearch.backgroundColor = [UIColor clearColor];
        codesearch.inputView = [[UIView alloc]initWithFrame:CGRectZero];
        codesearch.delegate = self;
        codesearch.tag = 1000;
        codesearch.placeholder = @"模糊搜索";
        [tint addSubview:codesearch];
        isclick = YES;
    }
    else
    {
        codesearch = [[UITextField alloc]initWithFrame:CGRectMake(780, 12, 100, 20)];
        codesearch.backgroundColor = [UIColor clearColor];
        codesearch.inputView = [[UIView alloc]initWithFrame:CGRectZero];
        codesearch.delegate = self;
        codesearch.tag = 1000;
        codesearch.placeholder = @"简码搜索";
        [tint addSubview:codesearch];
        isclick = NO;
    }
}
-(void)coderefresh:(NSNotification *)sender
{
    NSString *num = sender.object;
    obj = [searchproduct objectAtIndex:[num intValue]];
    [self ipadUI:obj shopid:numshopid shopname:nil tag:1];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"dismissPopover" object:nil];
}

-(void)suit:(UIButton *)sender
{
    if (sender.tag == 100000) {
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        NSString *colorcode = obj.pColorCode;
        [dic setObject:obj.pCode forKey:@"code"];
        [dic setObject:colorcode forKey:@"color"];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"suitrefresh" object:dic];
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        ProductObject *product = [similar objectAtIndex:sender.tag-100001];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        NSString *colorcode = product.pColorCode;
        [dic setObject:product.pCode forKey:@"code"];
        [dic setObject:colorcode forKey:@"color"];
        NSArray *suits_ = [[DataManager sharedManager] GetSuitArrayByCode:product.pCode ColorId:colorcode];
        if (suits_.count>0) {
            [[NSNotificationCenter defaultCenter]postNotificationName:@"suitrefresh" object:dic];
            [self.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"此产品没有对应配装" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        }
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
#ifdef DHH_iOS
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
#else
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
#endif
}

- (BOOL)shouldAutorotate{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
#ifdef DHH_iOS
    return UIInterfaceOrientationMaskPortrait;
#else
    return UIInterfaceOrientationMaskLandscape;
#endif
}


- (void)product_detail_image:(NSNotification *)notification{
    NSDictionary *dict = [notification userInfo];
    UIImage *img = [dict objectForKey:@"image"];
    //int tag = [[dict objectForKey:@"tag"] intValue];
    
    productImage_.image = img;
}
@end
